javascript - Overriding variable value inside the $.get() -
this question has answer here:
- how return response asynchronous call? 21 answers
i facing quite strange problem, dont seem able override variable jsondata inside success function of $.get()
$.fn.name = function(data, options) { var jsondata = data; var settings = $.extend({ .... }, options); if(typeof data !== 'object') { if(settings.debug) console.log('getting configuration settings from: ', data); $.get(data, function(d) { jsondata = d; //i attempt override value here }, 'json'); } console.log(jsondata); // gives same value before }; note: success event of $.get() triggered
by time logged value, $.get() has not overridden jsondata yet since ajax request has not returned time. console.log inside function instead.
$.get(data, function(d) { jsondata = d; //i attempt override value here - did! console.log(jsondata); }, 'json');
Comments
Post a Comment