我想下载在服务器上生成的.xls文件,到.xls生成时,我想锁定UI,但是在Ajax上,调用文件没有被下载,而数据在浏览器中出现,但它没有在浏览器上显示“另存为”对话框。
我的问题是,
1)我想下载在Jquery的Ajax调用服务器上生成的.Xls文件。
2)生成.xls文件时,我希望锁定UI.
Jquery的 (Ajax函数,.ajaxform) 不工作下载文件。
attr().submit()函数成功下载文件,但它没有通知文件下载完成的功能。
注意:1)从浏览器中启用“另存为”选项。
2) .Xls file is getting generated from server side successfully请提供任何可供选择的
发布于 2016-07-26 16:18:47
通过ajax是不可能做到的。你可以在你的成功回击中做些类似的事情。
window.location="download.xls/or/what/ever/?para1=value1...."并在服务器上设置适当的下载头。
发布于 2016-07-26 16:18:51
不幸的是,我们无法从AJAX请求下载文件
但是你可以用belo代码锁定屏幕
$("#id_of_form input[type='submit']").click(function(e){
// your code for lock screen here
return true;
});发布于 2016-10-18 11:52:47
我认为您想要跟踪下载状态(),U可以很容易地锁定您的UI,直到下载完成为止,我们可以用两种方式完成它,不幸的是,通过使用ajax调用我们无法启用下载文件,但是如果我们使用一些额外的html元素,我们可以启用jquery-ajax本身和您可以锁定您的UI直到jquery完成下载。
方法1
<a>标记并启用click事件,它将下载该文件。方法2
使用XMLHttpRequest而不是Jquery $ajax
xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function () {
var a;
if (xhttp.readyState === 4 && xhttp.status === 200) {
var _tempPPT = AQ.AMT.Url + "/Download/Template/ExportPPtTrend1.pptx";
// Trick for making downloadable link
a = document.createElement('a');
a.href = _tempPPT;// window.URL.createObjectURL(xhttp.response);
a.id = "idanchrPPT";
var k = xhttp.responseText;
// Give filename you wish to download
a.download = "test-file.pptx";
a.style.display = 'none';
document.body.appendChild(a);
a.click();
$("#idanchrPPT").remove();
//alert("ok");
$('.divLoader,.divBackgroundCo').hide();
}
};
// Post data to URL which handles post request
xhttp.open("POST", urlToHandler);
//Send the proper header information along with the request
xhttp.responseType = 'text';
//xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xhttp.send();https://stackoverflow.com/questions/38594955
复制相似问题