In our application we need to implement following scenario:
- A request is send from client
- Server handles the request and generates file
- Server returns file in response
- 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?
...retrieve data from, a server asynchronously without interfering with the display and behavior of the existing page.
So it won't interfere with the page and the data will only being stored in the JavaScript memory space. – Sarraceniaceous