setinterval (function () {
Ajax Request Background Data
},1000);
This is the A-page timer.
Then I jump to another page on page a after another request
The request to find the timer on page A behind the scenes is still executing
Why does this happen?
How can I jump to another page after the scheduled task does not execute it? weixinweiboqqqzoneyj327243832 | Browse 1987 times 2014-08-22 17:26 2014-08-23 11:03Best Answer
Personal feeling if the a page has been redirected to another page, then the request for that timer should not be executed again because the a page should have been destroyed in the browser.
Think you should take the time to test and determine if the request is made for the a page, such as the value of the request time on the request, which can help you analyze.
If you just don't perform a scheduled task, you can call Window.clearinterval before the page jumps to erase that timer.
12345 |
var g_intervalId; // 这要定义成一个全局变量 ... g_intervalId = window.setInterval(...); // 创建定时执行程序 ... window.clearInterval(g_intervalId); // 在跳转之前调用,以清除定时执行程序 |
The JS page uses the timer task to obtain the background data through Ajax, but after jumping from this page to other pages, the timed task still requests the background