Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8595301
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T00:24:08+00:00 2026-06-12T00:24:08+00:00

I want to download a file using jQuery Ajax web method, but it’s not

  • 0

I want to download a file using jQuery Ajax web method, but it’s not working.

Here is my jQuery ajax call to web method:

function GenerateExcel() {
   var ResultTable = jQuery('<div/>').append(jQuery('<table/>').append($('.hDivBox').find('thead').clone()).append($('.bDiv').find('tbody').clone()));
   var list = [$(ResultTable).html()];
   var jsonText = JSON.stringify({ list: list });
   $.ajax({
          type: "POST",
          url: "GenerateMatrix.aspx/GenerateExcel",
          data: jsonText,
          contentType: "application/json; charset=utf-8",
          dataType: "json",
          success: function (response) {

          },
          failure: function (response) {
               alert(response.d);
          }
            });
        }

and this is the web method definition:

[System.Web.Services.WebMethod()]
public static string GenerateExcel(List<string> list)
{
    HttpContext.Current.Response.AppendHeader("content-disposition", "attachment;filename=FileEName.xls");
    HttpContext.Current.Response.Charset = "";
    HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache);
    HttpContext.Current.Response.ContentType = "application/vnd.ms-excel";
    HttpContext.Current.Response.Write(list[0]);
    HttpContext.Current.Response.End();
    return "";
} 

How to get it done?

One more thing: I want to download it on client PC, not to save it on server.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T00:24:09+00:00Added an answer on June 12, 2026 at 12:24 am

    well i have done it using iframe

    this is the modified ajax function call

     function GenerateExcel() {
                var ResultTable = jQuery('<div/>').append(jQuery('<table/>').append($('.hDivBox').find('thead').clone()).append($('.bDiv').find('tbody').clone()));
                var list = [$(ResultTable).html()];
                var jsonText = JSON.stringify({ list: list });
                $.ajax({
                    type: "POST",
                    url: "GenerateMatrix.aspx/GenerateExcel",
                    data: jsonText,
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    success: function (response) {
                        if (isNaN(response.d) == false) {
                            $('#iframe').attr('src', 'GenerateMatrix.aspx?ExcelReportId=' + response.d);
                            $('#iframe').load();
                        }
                        else {
                            alert(response.d);
                        }
                    },
                    failure: function (response) {
                        alert(response.d);
                    }
                });
            }
    

    and this is the design part

     <iframe id="iframe" style="display:none;"></iframe>
    

    on Page load my code looks like this

     Response.AppendHeader("content-disposition", "attachment;filename=FileEName.xls");
     Response.Charset = "";
     Response.Cache.SetCacheability(HttpCacheability.NoCache);
     Response.ContentType = "application/vnd.ms-excel";
     Response.Write(tableHtml);
     Response.End();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i want to download a file using ajax via post request using jQuery. here
My question is similar to Download and open pdf file using Ajax But not
Using Django, I want to make some data available for download. My jQuery call
I want to give file download using java,struts2 and ajax. On my html page
I want to allow a user to download an html file using a php
I got a WPF application and I want to download a file. I'm using
I am using MEF in Silverlight for dynamic download .xap file. I want to
I want to download a wav file from a web service, cache it on
I want to download and save pdf file to internal storage. Here is code
I download a bz2 file using Python. Then I want to unpack the archive

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.