开发者

jquery ajax how to determine a server process is running or not

Project Type: ASP.NET 3.5 Language : C#

One of page uses Ajax Timer on page load.So while execution start, I start the timer using

this.AjaxTimer.Enabled = true;

This is used to start execution of a time consuming code like,

protected void AjaxTimer_Tick(object sender, EventArgs e)
{
    //Disable the Ajax Timer, so that it won't execute again after 500 ms
    this.AjaxTimer.Enabled = false;

    for (int i = 1; i < 140000; i++)
    {
     // Code here
    }
}

How do I know whether the process is completed or running wh开发者_如何学JAVAen I close the browser window using jQuery ?

OR

Simply, how can I know whether a server process is executing when I close the browser window? If it is running I want to abort it.

OR

How can I do the following stuff with jQuery

Script :

function abortRequest() {
    var obj = Sys.WebForms.PageRequestManager.getInstance();
    if (obj.get_isInAsyncPostBack()) {
        obj.abortPostBack();
    }
}

Markup:

<body style="background-color: Gray;" onunload="abortRequest();">
    <form id="form1" runat="server">
    </form>
</body>


You may use the same code to test the whether server side script is running or not. But you may write the code inside document.ready function

$(document).ready(function(){
    var obj = Sys.WebForms.PageRequestManager.getInstance();
    if (obj.get_isInAsyncPostBack()) {
        obj.abortPostBack();
    }
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜