skip to Main Content

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


  1. Chosen as BEST ANSWER

    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


  2. Create hidden input tag (Variable) on that page and store first value of ajax
    Like :

    <input type="hidden" name="result_store" id="result_store">
    

    compare that value to second ajax result

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search