How to specify content
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.
There is no way I know of to get a true Ajax request to pop a save dialog up. This has nothing to do with the headers sent by the server.
If you'd like to programatically pop a save dialog box, you can use jQuery to append a hidden iframe to the page with the URL as it's src. This should pop the dialog box as necessary.
That's something the server has to do. There's nothing you can do from the client side that will force an unwilling server to set response headers.
链接地址: http://www.djcxy.com/p/46268.html上一篇: 无法显示“application / octet”类型的响应
下一篇: 如何指定内容