How to send an Ajax request for every 1 using jQuery?
You probably do not want to send a request every second, as David already noted.
Therefore, using setInterval is a bad idea.
setInterval
Instead, do the following:
function doAjax() { $.ajax({ ... complete: function() { setTimeout(doAjax,1000); //now that the request is complete, do it again in 1 second } ... }); } doAjax(); // initial call will start rigth away, every subsequent call will happen 1 second after we get a response
you can use setInterval, but setInterval is not part of jQuery:
setInterval(function() { $.get(...); }, 1000);
The interval of 1 second is small enough, and you can run the second request before receiving a response to the first request . Therefore, you must either start the next request after receiving the previous one (see Martin Jespersen's proposal), or save jqXHR from the previous $.ajax request in a variable and use it to abort the previous request (see the example here )
jqXHR
$.ajax
setInterval(myAjaxCall, 1000);
Obviously, in the myAjaxCall () function, you will do whatever you want with jquery.
if you use the setInterval method, you can crush the browser because setInterval does not wait for the ajax function to complete, if the server is slow or the user connection speed is slow, this may be the reason for running several ajax requests the same time
Source: https://habr.com/ru/post/1343748/More articles:Redirecting after login results in a 404 error if the user submits the form to the POST-only action and their authentication is complete - asp.net-mvcnant task - c #SQL SELECT with default value - sqlTINYMCE set focus ... just won't work - javascriptWhy create a new tutorial on an object - Java Tetris - javaUse do_mmap () in Linux device driver - cQuartz.net: FireAtTime not working properly - c #Reading zip file from url with php - phpAndroid 1.6 setZOrderOnTop alternative - androidUnknownHostException in android - androidAll Articles