im working on a project using asp.net mvc. and im trying to read data from sql server every 5 second and update the user with some feedback.
what I've done till now is using ajax call combined with set timeout. so every 5 second use ajax call to check if there any new data as shown below.
( the URL is just an example)
function ajaxRequest() {
$.ajax({
url: "https://jsonplaceholder.typicode.com/photos",
success: function (result) {
console.log(result);
},
complete: function (data) {},
}).then(function () {
setTimeout(ajaxRequest, 5000);
});
}
my question is, is there any down side for using set timeout or set interval with ajax like this? or if there is any better solution for my problem.
worth to mention that the project will be used by at max 4 users at the same time. so I don't think over-loading the server with request will be a problem.