0

AJAX リクエストを使用してグローバル変数を更新する方法を理解しようとしています。立ち往生していて、助けが必要です。

var markerArray = [];

function JSONload(position){ //Loads JSON and markers
console.log("data getting jsoned");
$.getJSON('json/***.json', function(result){ //gets the json and parses it into results
    $.each(result, function(index, value){ //for each result, give the index and the value    
    reps.push({value: value, index: index}); //push the value at to the array. ex. Ian Calderon 
    }); 


   try{ 
    for (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 to create the marker if there is the values
         updateArray(markerArray, marker);

            }}}
   catch(e){
   }
    });

}

私はこれをやってみました:

function updateArray(array, obj){
$.ajax({
    success : function(){
        array.push(obj);
    }
}
    );

でも率直に言って、どうやって進めばいいのか分からない

4

1 に答える 1