It seems that you managed to get the delay argument setTimeoutwritten in the wrong place.
$(document).ready(function() {
(function poll() {
setTimeout(function() {
$.ajax({
url: "/project1/api/getAllUsers",
type: "GET",
success: function(data) {
console.log("polling");
},
dataType: "json",
complete: poll,
timeout: 5000
})
}, 5000);
})();
});
If you follow the curly braces, you will see what you call setTimeoutlike:
setTimeout(function () {
$.ajax(), 5000
})
and should be
setTimeout(function () {
$.ajax();
}, 5000)
This should trigger AJAX polling 5 seconds after completing the previous one.
source
share