javascript - Global variable doesn't get assigned the value -


i can't figure out.

i have global variable named id.

when call function below id doesn't return value of msg in less use bottom alert('inside bottom4 (id) =' + id). if comment out alert, id value of global variable before calling function.

oh btw, alert('after assignment=' + id); has correct return value.


var id = 0;  savetodb(obj);  alert(id)  function savetodb(lcalevent) {     var thingid = parseint(lcalevent.userid);      $.ajax({         type: "get",         url: "res_update.asp",         data: "id=" + lcalevent.id,         success: function (msg) {             if (msg.indexof('following') > 0) {                 notices.show('error', msg, { duration: 1000 });                 $("#calendar").weekcalendar("refresh");             } else {                 if (msg != '0') {                     id = msg++; alert('after assignment=' + id);                 }                 notices.show('notice', 'your reservation has been saved');             }         },         error: function (msg) {             alert("data error: " + msg);         }     });  alert('inside bottom4 (id) =' + id) } 

ajax asynchronous.

you success callback runs time after rest of code.


Comments

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -