I’d like to check if the first value I get of an AJAX call is bigger than the next ones. Somehow I can’t figure out how to do it. Every 5 seconds I check the value of followers.
let callFollowers = () => {
$.ajax({
url: 'https://api.instagram.com/v1/users/self',
dataType: 'jsonp',
type: 'GET',
data: {
access_token: token
},
success: (result) => {
let followers = result.data.counts.followed_by,
counter = document.querySelector('#counter');
let splitToDigits = (followers) => {
return [...followers + ''].map(Number);
};
counter.innerHTML = '';
for (let i = 0; i < splitToDigits(followers).length; i++) {
let appendChild = document.createElement('span');
appendChild.innerHTML = splitToDigits(followers)[i];
counter.appendChild(appendChild);
}
console.log(followers);
}
})
};
callFollowers();
window.setInterval(callFollowers, 5000);
2
Answers
Place the value in a variable defined outside of the success handler in each call. Compare the new value to the old one and perform whatever action you need. Finally, update the value to that of the current request.
Thanks @Rory McCrossan
Create hidden input tag (Variable) on that page and store first value of ajax
Like :
compare that value to second ajax result