mawimawi
mawimawi

Reputation: 4333

Jquery ajax function and downloading files

I am using $ajax( { type:"post", url:"/whatever/" } ) to access my server which works nicely. The problem is that the response is not evaluated as I need it. On some occations the server sends back a dummy string ("x") which can be ignored on the browser, but on other occasions my server sends back a special file as attachment:

mimetype application/x-my-special-type
Content-Disposition attachment; filename=myname.ext
....

But the browser (I am only interested in Google Chrome / Chromium - it's an intranet thing) does not show the download popup window. (Calling the "/whatever/" URL directly in the address bar actually DOES show the download popup window to save the file.)

How can I persuade jQuery to show the usual download popup window?

Upvotes: 0

Views: 1472

Answers (1)

spender
spender

Reputation: 120380

Send the user to the URL by setting window.location.href or linking directly to the file. Do not use AJAX for this, as it is only used for retrieving data to variables/inserting to DOM. You'll probably need to think of a different way to represent the no-response case. Perhaps the AJAX portion could be used to establish if a file is available or not, and the redirection would occur if the AJAX response indicates that a file is available.

Upvotes: 2

Related Questions