jquery - Javascript "global" variable issue -


    var desc;     $.ajax({         url: "data/step2.xml",         datatype: "xml",         success: function(data){             $(data).find('date').each(function(){                 var day = $(this).find('day').text();                 var date = $("#txtdate").datepicker("getdate");                 date = (date.getdate()+"-"+date.getmonth()+1+"-"+date.getfullyear());                 if (day==date){                     $(this).find('availability').each(function(){                         var prod = $(this).find('product').text();                         var time = $(this).find('starttime').text();                         if (prod==label){                             desc="!";                         }                     });                 }             });         }     }); 

i'm having issues accessing desc variable... want manipulate it's value can see in desc="!", returns undefined. isn't there way make variable global or something? or other way access it? ... oh, , code inside function.

in particular case problem not scoping of desc variable. desc variable manipulate in success callback same 1 declared before ajax call.

the problem here timing. success method doesn't execute @ same time ajax call made. executes time later when ajax call completes. @ point value written desc. code handles desc value must called point desc value set

if (prod == labe) {    desc = "!";   ondescchanged(); } 

Comments

Popular posts from this blog

how to insert data php javascript mysql with multiple array session 2 -

multithreading - Exception in Application constructor -

windows - CertCreateCertificateContext returns CRYPT_E_ASN1_BADTAG / 8009310b -