I'm doing AJAX-requests within an Intervalfunction in Javascript (e.g. once every 10 seconds).
I want to store the response (text ~ of the previous request) in a Javascript variable.
When the next request takes place, I want to check if the new response matches the previous one or not.
Something like:
var temp_data = response; //store response here
var final_data;
if(){
final_data = temp_data;
}
else {
}
Need soms advice/help,
Thanks!
Solved by storing responses in an array and slicing existing and pushing new object.
if (ajaxResults.length < 2) { //As long as arraylength < 2
ajaxResults.push(data); //Add object (executed for 2 objects)
} else if (ajaxResults.length == 2) { //
ajaxResults.splice(0, 1); //Remove 1 object at index 0, next element that was in array goes to index 0
ajaxResults.push(data); //Add last response to the end of array with push() = at index 1
}