我有一个 extjs ajax 函数,它将表单发送到服务器,服务器返回一个要下载的文件,其中包含正确的 Content-Disposition ="attachment; filename='test.zip'"
header 。可以使用浏览器的正常文件下载窗口下载该文件。但是,ajax请求的成功回调函数没有被触发,ajax处于pending状态,无限期等待响应。
有没有办法告诉ajax函数文件是否从服务器正确发送?
exportLayer = function(node_id){
Ext.Ajax.request({
method: "GET",
form: "exportForm",
url: "/basqui/layer/shapefile/export/" + node_id + "/",
success: function(r){
html = Ext.decode(r.responseText).html
Ext.get('pageContent').update(html);
},
});
}
最佳答案
设置Ext.Ajax.request
的binary
配置属性,并在您将得到的响应中
responseBytes
属性内的二进制数据。
例如加载 jpeg 图像:
Ext.Ajax.request({
url: "/path/to/image/test.jpg",
success: function(xhr) {
var b64encoded = btoa(String.fromCharCode.apply(null, xhr.responseBytes));
var img = Ext.create('Ext.Img', {
src: 'data:application/jpeg;base64,' + b64encoded
});
// add image somewhere
...
}
});
关于javascript - Ajax - 了解文件下载是否从服务器正确发送,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24577666/