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

Source: Internet
Author: User

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 varg_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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.