Download File Using Ajax

Download File Using Ajax 5,0/5 9179 votes

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.

  1. Download File Using Ajax Call
  2. Download File Using Ajax Php
  3. Ajax Download Zip File
Active1 year, 11 months ago

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:

Free pascal compiler download

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.

Dmytro
8,74422 gold badges60 silver badges111 bronze badges
rahulrahul
6,2214 gold badges31 silver badges43 bronze badges

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

rahulrahul
6,2214 gold badges31 silver badges43 bronze badges
  1. Add these in your view page-

  2. Server side

  3. Add this code in your JavaScript

That should work!

Download File Using Ajax Call

Mogsdad
34.9k12 gold badges103 silver badges216 bronze badges
vanshika pandeyvanshika pandey

Assuming the C# code responds with the correct headers for Excel, you can simply redirect to the link instead of using ajax:

LianLian

Download File Using Ajax Php

1,3001 gold badge8 silver badges12 bronze badges

Ajax Download Zip File

Not the answer you're looking for? Browse other questions tagged c#jquerywebmethod or ask your own question.