views:

24

answers:

0

Hello everybody.

I want to make some ajax requests in cycle with jquery.ajax method. And I must handle the link request id(some information passed to server) -> server response after all requests done. And so on I have not any information about request id in server response. How could I handle this? May be handle request data in callback context?

SRManager.postAjaxJSON = function(url, jsonData, successCallBack) {
    jQuery.ajax( {
        url : url,
        type : 'POST',
        data : jsonData,
        contentType : "application/json",
        processData : false,
        dataType : 'json',
        success : successCallBack
     });
};
SRManager.getFriendsGames = function(ids,callback){    
    for(i = 0; i<ids.length; i++){
        var jsonData = JSON.stringify( { "friendId" : ids[i] });
        SRManager.postAjaxJSON(SR_DOMAIN + REST_GET_FRIEND_GAMES, jsonData, function(result){
            Social.results.push(result);
        });
    }
    Social.interval = setInterval(function(){
        if(Social.results.length != ids.length) return;
        clearInterval(Social.interval);
        if(callback != null) callback(Social.results);
    },200);
};
SRManager.getFriendsGames([1,2,3],function(result){ 
    //Here I must find the data in result wich linked with elements in parameter array.
});

After this I have the interval wich call a method after all requests done. In this method I whant to see link between "friendId" and Social.results[i]. I could add friendId in Social.results in callback of ajax request but how could I get this friendId in that context?