[英]How can I download file loaded by XMLHTTPRequest via Ajax
我想下載文件,現在我正在使用window.location.href,但是它使用我的servlet的第二次調用來生成文件,並且文件生成大約1分鍾,如何從XMLHTTPRequest下載它。 它只能與Internet Explorer 7+一起使用。如何在沒有window.location.href的情況下獲取文件
Ext.Ajax.request({
url : fileUrl,
success : function(response){
var resp = response.responseText;
if (resp.indexOf('error')>-1){
//some logic
}else{
window.location.href = fileUrl;
}
}
}
});
您無法使用XMLHTTPRequest下載文件。 因為您要支持IE7 +,所以我建議使用IFrame並在IFrame上設置src。 不要忘記服務器的標頭必須包含Content-Disposition: attachment;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.