Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
29
rated 0 times [  36] [ 7]  / answers: 1 / hits: 74022  / 12 Years ago, mon, february 4, 2013, 12:00:00

In our application we need to implement following scenario:




  1. A request is send from client

  2. Server handles the request and generates file

  3. Server returns file in response

  4. Client browser displays file download popup dialog and allows user to download the file



Our application is ajax based application, so it would be very easy and convenient for us to send ajax request (like using jquery.ajax() function).



But after googilng, it turned out that file downloading is possible only when using non-ajax POST request (like described in this popular SO thread). So we needed to implement uglier and more complex solution that required building HTML structure of form with nested hidden fields.



Could someone explain in simple words why is that ajax requests cannot be used to download file? What's the mechanics behind that?


More From » ajax

 Answers
10

It's not about AJAX. You can download a file with AJAX, of course. However the file will be kept in memory, i.e. you cannot save file to disk. This is because JavaScript cannot interact with disk. That would be a serious security issue and it is blocked in all major browsers.


[#80440] Friday, February 1, 2013, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
santana

Total Points: 595
Total Questions: 94
Total Answers: 98

Location: Zambia
Member since Mon, Oct 24, 2022
2 Years ago
;