Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Call jQuery Ajax Request Each X Minutes

Tags:

jquery

ajax

timer

How can I call an Ajax Request in a specific time Period? Should I use Timer Plugin or does jQuery have a plugin for this?

like image 819
Shahin Avatar asked Feb 08 '11 07:02

Shahin


People also ask

How do you call AJAX every 5 seconds?

Using setInterval() It repeatedly calls the function on the given interval for stop you need to clear the interval using clearInterval() or close the window. Creating a function that calls the AJAX request and using this function in setInterval() and set Interval for 5 sec.

What is AJAX synchronous call?

Synchronous API call means Javascript thread will stop further execution of code until this Ajax request gets resolved. Since the main thread is blocked waiting for request to get completed, your browser will stop responding to events (it will become unresponsive).

Are AJAX calls slow?

In my app, there are a lot of ajax calls. A user may do 50 ajax calls per session, so speed is very important.

Does AJAX wait for response?

ajax() function with the default settings, any JavaScript code after this AJAX request will be executed without waiting for a response. In most cases, this is the desired behavior, but there are some situations where you will want to prevent further execution until there has been a response to the AJAX call.


1 Answers

You can use the built-in javascript setInterval.

var ajax_call = function() {   //your jQuery ajax code };  var interval = 1000 * 60 * X; // where X is your every X minutes  setInterval(ajax_call, interval); 

or if you are the more terse type ...

setInterval(function() {   //your jQuery ajax code }, 1000 * 60 * X); // where X is your every X minutes 
like image 90
Ben Avatar answered Oct 02 '22 04:10

Ben