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?
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.
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).
In my app, there are a lot of ajax calls. A user may do 50 ajax calls per session, so speed is very important.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With