0

I'm trying to select data out of jQuery and input it into if statement:

setInterval(function()
    {
      $.getJSON("IOCounter.html", function(data) 
      {
        $('#statusInt_1').text(data.statusInt_1);
      });
    },
    1000); //Refreshrate in ms
    }); 


if (data.statusInt_1==1)
 {
   $('#Loading').toggleClass('standby');
 }
})

My if doesnt select "data.statusInt_1". What am I missing?

Sfedo
  • 21
  • 1
  • 8
  • `getJSON` is async, `data` has scope of callback function, don't use timeout to try "wait" for async requests – Justinas Aug 27 '20 at 13:07
  • 1
    I dont understand anything – Sfedo Aug 27 '20 at 13:14
  • The if statement should be with the line `$('#statusInt_1').text(data.statusInt_1);` – epascarello Aug 27 '20 at 13:18
  • https://stackoverflow.com/questions/23667086/why-is-my-variable-unaltered-after-i-modify-it-inside-of-a-function-asynchron – epascarello Aug 27 '20 at 13:18
  • @epascarello ok I did it like this: if ($('#statusInt_1').text(data.statusInt_1)==0) but it still doesnt work. – Sfedo Aug 27 '20 at 13:24
  • What? Just move the if statement up, why did you do that? That if statement says if a JQuery object is equal to zero. – epascarello Aug 27 '20 at 13:26
  • I am a noob, I dont understand. Ok I have to move the if statement up into setInterval(function() in the line $('#statusInt_1').text(data.statusInt_1);. But how? where do I have to place if? – Sfedo Aug 27 '20 at 13:36
  • @epascarello I did it as you said, and it works, but now I'm refreshing the if statement, what I dont want to do. I just need to refresh the condition of if statement, not the content – Sfedo Aug 27 '20 at 13:56

0 Answers0