Javascript not working as per logic -


this question has answer here:

i have been struggling last whole night find bug not find. javascript code not working should.

var currcab = 0; var cabbooked = 0;  function sendmessage(cabid)  {     if(cabbooked == 1) {         return;     }      // data html page       $.post("sendmessage.php",data,            function(data,status){                                  $("#status").html(data);            }); }  function checkbookingstatus() {     var data = "bookingid="+$("#bookingid").val();     $.post("checkbookingstatus.php",data,            function(data,status){                // callback here                var ans = data.indexof("true");                if(ans!= -1) {                    console.log("returning true checkbookingstatus");                    $("#simplestatus").html("cab booked. can close tab now");                    cabbooked = 1;                    return true;                } else {                    console.log("returning false checkbookingstatus");                    return false;                }            });    }   function trycaballoc() {     if(!checkbookingstatus()) {         if(cabbooked == 1) {             return;         }          var checkid = document.getelementbyid("cabid"+currcab);         if(checkid==null) {             $("#simplestatus").html("cab not booked.");             $("#status").html("no more clients communicate with.");         } else {             var cid = $("#cabid"+currcab).val();             sendmessage(cid);             updatetrying(cid);              currcab = currcab + 1;         }     } }  $( document ).ready(function() {     $("#simplestatus").html("please wait. communication being started...");     $("#status").html("gcm push initiating ...");      trycaballoc();      setinterval(function(){         if(cabbooked==0) {             trycaballoc();         } else {             throw '';         }     },95000);  }); 

the code should stop working when checkbookingstatus returns true , cabbooked set 1. not stopping @ all. have no idea why.

if(!checkbookingstatus()) { continue if it's false, not if it's true per comment.


Comments

Popular posts from this blog

c++ - QTextObjectInterface with Qml TextEdit (QQuickTextEdit) -

javascript - angular ng-required radio button not toggling required off in firefox 33, OK in chrome -

xcode - Swift Playground - Files are not readable -