asynchronous - ASync Array update with AJAX request -
i've been trying figure out how update global variable using ajax request. i'm stuck , need help.
var markerarray = []; function jsonload(position){ //loads json , markers console.log("data getting jsoned"); $.getjson('json/***.json', function(result){ //gets json , parses results $.each(result, function(index, value){ //for each result, give index , value reps.push({value: value, index: index}); //push value @ array. ex. ian calderon }); try{ (var i=0; i<reps.length; i++){ if(reps[i].value.lat !== 'undefined' && reps[i].value.position === position){ var marker = (createmarker(reps[i].value.lat, reps[i].value.long, reps[i].index)); //only try create marker if there values updatearray(markerarray, marker); }}} catch(e){ } });
}
i have tried doing this:
function updatearray(array, obj){ $.ajax({ success : function(){ array.push(obj); } } );
but frankly i'm not sure how proceed
i think function scope throwing off.
try this:
var = this; console.log("data getting jsoned"); updatearray(that.markerarray, marker);
the variable should have access global variable in function.
Comments
Post a Comment