Reputation: 2640
From the self Host I want to get the data after every 5 seconds.
My Code in request.js:
$.ajax({
type: "GET",
url: "http://localhost:8080/api/Data",
success: function (data) {
console.log(data);
}
});
What do I have to add?
Upvotes: 3
Views: 4343
Reputation: 2707
Write function and set it to setInterval
:
function checkData() {
$.ajax({
type: "GET",
url: "http://localhost:8080/api/Data",
success: function (data) {
console.log(data);
}
});
}
setInterval(checkData, 5000);
you can use setTimeout
if your ajax call gets longer time to get response:
function checkData() {
$.ajax({
type: "GET",
url: "http://localhost:8080/api/Data",
success: function (data) {
console.log(data);
setTimeout(checkData, 5000);
}
});
}
setTimeout(checkData, 5000);
Upvotes: 7