I would like to make an async GET request that returns back a document with MIME content type and cause it to bring the browser's 'Save' dialog.
Previously, I used to make a regular HTTP (non-async) call through a link and the returned response had a 'Content-Type' and 'Content-Disposition' like so:
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 to jQuery's $.ajax() GET request?
The $.ajax method only supports the dataTypes, "xml", "html", "script", "json", "jsonp", and "text". Would my response data-type fall into one of these categories?
My request 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 the file contents passed back in the 'data' variable as a plain text but need the 'save' dialog to get launched on the browser.
The server IS sending back the response with the correct headers set.