I have written ajax which gets called every second using setInterval()
function.
I want to use the ajax response to set text content of a span using innerText.
ajax is getting called every second and is receiving response data from URL.
When data from response remains unchanged for 5 seconds, I want the text content of span tag to be removed.
How can I put condition in ajax call to check if data from response is unchanged for 5 seconds?
setInterval(function() {
$.ajax({
type: "POST",
url: "/data", // URL to your view that serves new info
})
.done(function(data) {
console.log(data);
});
}, 1000)
Any suggestion will be appreciated.
Thank you in advance.
2
Answers
Try something like this:
Record the time and the data whenever the data changes.