No, it's not possible to do this by AJAX.
BTW, you can do redirect to the file, if you need. It'll be requested in a separate request then.
Ajax is used for partial page update. Trying to download anything also, it a bad idea by definition.
When you click on the regular link to download html or binary file, the request is sent by the browser itself. Then, when response comes, the browser decides what to do with it (to show in the window as a new document or open by an external program or offer the saveas window)
When the Ajax request performs, it is sent by the XMLHTTPRequest object. The object expects that response is in the XML format. XMLHTTPRequest object cannot launch the external program based on the content type or saveas dialog, because XMLHTTPRequest != browser. It has no permissions for such operations.
Thank you guys for the detailed answers it clears up the internals of ajax very much. The reason why that behavior might be useful is when I want conditionally handle ajax request and in some cases return a file, otherwise report an error and continue work in the existing page, only performing some rerendering.
I hope redirect would help. Does redirect work for ajax request?
Yes, redirect should work ok.