mardi 2 juin 2020

Why code inside if loop is not executing even when condition is true?

I am fetching json data from server using ajax in every 8 second . it work fine most of the time but sometime code inside 2nd if loop is not executing even when condition is true.

setInterval(function () {
  if (board.turn != board.mycolor) {
    $.ajax({
      type: 'post',
      url: 'checkgamedata.php',
      success: function (result) {
        var obj = JSON.parse(result);

        if (players[board.turn].lastturnno < obj.turnno) {
          //Code inside this if loop is not executing

          players[board.turn].lastturnno = obj.turnno;

          for (var i = dataleft; i < obj.kodidata.length; i++) {
            numbergot = grandom(obj.kodidata[i]);

            process(numbergot);

            if (obj.indexarr[i] != 'null') {
              updatepawn(obj.indexarr[i]);
            }
          } //For loop end

          if (board.turn != board.mycolor) {
            dataleft = obj.kodidata.length;
          } else {
            dataleft = 0;
          }
        }
        //If loop end
      } //Success end
    });
  }
  //Post end here
}, 8000);
//timeout end here

My result of ajax operation is something like this {"kodidata":[["0.33","0.40","0.36","0.76"]],"indexarr":["2"],"turnno":"12"}.

I checked value of obj.turn and players[board.turn].lastturnno just before if loop by using alert and i can see that obj.turn value is greater but still code inside if loop is not executing .why?

Aucun commentaire:

Enregistrer un commentaire