JavaScript callBack Gets Ran Twice - Should Only Run Once? -


i clarify first have searched solution answer on 2 hours , cannot seem locate solution.

i have function addproductcheck();

this function called on item click , seems working no difficulty. problem arises when next function callback ran.

cartproductexists(objectvars, function(cartitem) {  } 

this designed run asynchronous call database, check item inside cart table, , return callback results further manipulation.

cartproductexists(objectvars, function(cartitem) {      if (cartitem != null) {     //ran after callback returns cartitem no longer null     }else{     //gets ran first time cartproductsexists called, when shouldn't.     }  } 

i not sure going wrong this, knowledge rest of code inside callback shouldn't getting ran until callback triggers response.

can me problem?

if (cartitem == null || cartitem == "") {     //ran after callback returns cartitem no longer null } else {     //gets ran first time cartproductsexists called, when shouldn't. } 

can try in way?


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -