Arn*_*sss 5 asp.net jquery web-services
我正在调用一个生成Excel文件的Web服务,完成后用户可以下载该文件。生成此文件大约需要20秒。有没有一种使用jQuery的方式向用户提供一些反馈,而状态栏除外。我更喜欢不保存或缓存文件在服务器端。
我曾希望像下面这样的东西可以工作,但是显然没有用
var myhref = "DownloadFile.ashx?foo=bar"
$.get(myhref, function (data) {
window.location = this.href;
},
function (data) {
alert("Could not generate file");
});
Run Code Online (Sandbox Code Playgroud)
所以我想要的是在生成下载时保持ui处于活动状态
小智 2
当我想用ajax执行一些操作时,我遇到了类似的问题,这些操作不需要太多时间,但足以让用户思考“发生了什么事?它正在做我想要的事情吗?”。
我发现了一个名为blockUI的 jQuery 插件(真的很酷!),它会在您处理内容时显示一条消息。
这是我的使用方法。首先是处理请求的函数:
function proceedToSend( requesterName, requesterId )
{
//Here the wait/processing message is displayed
$().ajaxStart($.blockUI({ message:$('#waitMessage')}));
$.ajax({
type :"POST" ,
url : http://example.com/myurl.php
dataType: yourDataType ,
data : myData ,
success :function ( response )
{
//response processing if needed
// Here the wait/processing messages is hidden
$().ajaxStop($.unblockUI({ message:null }));
} ,
error :function ()
{
alert('there was an error processing the request!!');
$().ajaxStop($.unblockUI({ message:null }));
}
});
}
Run Code Online (Sandbox Code Playgroud)
最后,您必须将其添加到页面上,以便显示消息:
<div id="waitMessage" class="dataContainer" style="display: none;">
<p style="font-size: 30px;">Processing request...</p>
</div>
Run Code Online (Sandbox Code Playgroud)
就是这样,希望有帮助!;)