开发者

Running Tasks Before Redirect

We have a timer process (a JQuery plugin) that redirects after X number of minutes to the login page, all via JavaScript. When the timer hits zero, I want to run a task (could be anything; however, in this specific scenario, it's a web service call).

So the process does:

if (zeroedOut) {
  window.setTimeout(function() {
    //Run finish-up processes
  }, 0);

  window.location = "login.aspx";
}

The issue I'm having is the web service that runs with the finish-up processes is not being called. The 开发者_如何学Pythonweb service call happens, the redirect happens, I don't see any errors (I have try/catch statements around the setTimeout call), but no WS call.

Has anybody got this to successfully work? What might I be missing here?

Thanks.


Why isn't your redirect in the setTimeout call? Otherwise, the redirect will happen before the queued code can run.

if (zeroedOut) {
  window.setTimeout(function() {
    //Run finish-up processes
    window.location = "login.aspx";
  }, 0);
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜