I have loop that cycles through multiple asynchronous AJAX calls. The call is fed the loop iteration as an index. When the call is completed, the data is stored in an array depending on the index.
However, the index returned in the success function is different than the index fed to the initial AJAX call. Is there a good way for the call to return the same index upon success that the call was initially fed?
var ptype = 'fp';
var pnum = 2;
var data = new Array();
for(var i = 1; i <= 5; i++){
call_general_forecast(ptype,i,pnum);
}
function call_general_forecast(ptype, i1, pnum1){
index = pnum1*5 + i1;
$.ajax({
url: '',
data : { stock_name : stock_name, pattern: ptype, specificity : i1},
type : 'get', //or 'post', but in your situation get is more appropriate,
dataType : 'json',
success : function(r) {
data[index] = r;
alert(index);
},
async: true
});
}