jquery - Parts of ajax function can just be reached by debugging -
i have asp.net application in user jquery. in jquery code have simple ajax request this:
var allowdelete = true; $.ajax({ url: '...', datatype: 'json', type: 'post', data: { something...} }) .success(function (response) { if (response.passed) { //do } else { //do allowdelete = false; } }) .error(function () { // }); if (allowdelete) { //something }
as can see want var set false when passed var has value false. when run code without breakpoints allowdelete var never set false. , when put breakpoint(in firebug) next row set allowdelete false never hits breakpoint. when put breakpoint @ beginnig of function , debug through whole ajax works fine , result wanted. idea mistake be?
since asked question more 1 month ago, might late, hope helps:
the reason ajax asynchronous: 1. set allowdelete true. 2. call ajax function. starts working, turns server, etc. 3. check allowdelete. still true. 4. ajax call returns, sets allowdelete false if conditions ok (response not passed).
so because of asynchrony, allowdelete being checked right after call ajax function, doesn't wait answer(the ajax callback method). basically, ajax functions callback method runs late.
when use breakpoint, ajax call has enough time answer server fourth point above happens earlier third.
Comments
Post a Comment