I would like to make an async GET request that will return a document with the MIME content type and make it display the browserโs Save dialog.
I used to make a normal HTTP call (non-asynchronous) by reference, and the response returned had "Content-Type" and "Content-Disposition", for example:
Content-Type: text/plain Content-Disposition: attachment; filename=genome.jpeg; modification-date="Wed, 12 Feb 1997 16:29:51 -0500";
Is there a way to convert this into a jQuery $ .ajax () GET request?
The $ .ajax method only supports data types: "xml", "html", "script", "json", "jsonp" and "text". Will my response data type fall into one of these categories?
My query looks like this:
$.ajax({url: myUrl, data: params, type: "GET", success: function(data) { console.log("try to save this file!"); }, error: function(req, status, errThrown){ alert("ERROR: Something happened"); }
In the success callback, I see that the contents of the file are passed in the data variable as plain text, but the save dialog box is required to open in the browser.
The server sends a response with the correct set of headers.
source share