Download File Using Ajax
I have an ajax function that exports a database of contacts to a.csv file, and just after it finishes, it automatically starts the.csv file download. So, after I get the responseText and everything is Ok, I redirect browser like this. Hi, From Jquery ajax i am making a C# function call which is returing a file download option. If i am using $.ajax, it is not working, if i am giving window.location = url then that download box is coming.
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:
and this is the web method definition:
How to get it done? Please help me out.
One more thing: I want to download it on client pc, not to save it on server.
3 Answers
well i have done it using iframe
this is the modified ajax function call
and this is the design part
on Page load my code looks like this
rahulrahulAdd these in your view page-
Server side
Add this code in your JavaScript
That should work!
Download File Using Ajax Call
MogsdadAssuming the C# code responds with the correct headers for Excel, you can simply redirect to the link instead of using ajax:
LianLian