Home > Web Front-end > JS Tutorial > body text

JS implements scheduled tasks to request background setInterval timing and ajax request issues every N seconds

韦小宝
Release: 2018-01-12 09:53:06
Original
2374 people have browsed it

This article mainly introduces JS to implement scheduled tasks to request the background every N secondssetInterval timing and ajax request related JS information, friends who are interested in js can refer to this article

Look at the following piece of code first:

DiGui = function (param) {    
$.ajax({ 
 success: function (returnValue) {
  window.setInterval("fnSetMarkPoint()", 5000); 
 }
});
Copy after login

After calling the DiGui() method

Problem: Create a setInterval every 0.1 seconds in a tree shapeLoopCreate setInterval until the page crashes

Solution: Ensure that setIntervalobject is only created once

Implementation plan: Define a Boolean variable for judgment var status= true;

var status = true;
DiGui = function (param) {    
$.ajax({ 
 success: function (returnValue) {       
  if (status) {
   status= false; 
       window.setInterval("DiGui()", 5000); 
    }
   } 
 });
Copy after login

The above is the JS implementation of scheduled tasks introduced by the editor to request background setInterval timing and ajax request issues every N seconds. I hope it will be helpful to everyone! !

Related recommendations:

JS to remove all commas in a string Example detailed explanation

JS to move elements up, down, left, and right

js example of how many days are the difference between two dates

The above is the detailed content of JS implements scheduled tasks to request background setInterval timing and ajax request issues every N seconds. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!