业务逻辑: 下载txt文件,因数据量较大,等待时间过长,需要做页面等待提示,下载完成后要关闭,并没做进度条提示
解决思路:reponse写一个cookie过来 每次下载完 更新cookie的值 页面定时检查cookie值是否更新
代码
//检测cookie函数,如果cookie为空则跳转到登陆页
function checkCookie() {
var fileDownloadStatus = getCookie('fileDownloadStatus');
var oldFileStatus = $("#fileDownloadStatus").val();
if((oldFileStatus.length == 0 && fileDownloadStatus.length > 0)
|| (oldFileStatus.length > 0 && fileDownloadStatus.length > 0 && fileDownloadStatus != oldFileStatus)) {
$("#fileDownloadStatus").val(fileDownloadStatus);
closeLoading();
}
}
function getCookie(cookieName) {
var strCookie = document.cookie;
var arrCookie = strCookie.split("; ");
for(var i = 0; i < arrCookie.length; i++){
var arr = arrCookie[i].split("=");
if(cookieName == arr[0]){
return arr[1];
}
}
return "";
}
<input type="hidden" id="fileDownloadStatus"/>
//每隔1秒,执行cookie检测函数
setTimeout("checkCookie()",1000);