Currently I go through a number of elements using the each function
and for each element I do an ajax call, the result of each ajax call
should then replace the content of the corresponding element. When I
started working on it, it sounded ridiculously easy, however I am
unable to identify which element corresponds to which ajax response
function, due to the fact that the ajax call is asynchronous to the
script. Here is the main part of the script:
$(".shorten").each(function(){
element = this;
$.getJSON("http://safe.mn/api/?format=jsonp&url=" + escape($
(this).attr("id")) + "&callback=?",
function(data){
// element will be the last element in the each loop
}
);
});
I have no clue at all anymore on how to solve it, so a pointer in the
right direction would be more then appreciated. Essentially all I need
is to pass a variable from outside the ajax call - at the point the
ajax call is launched - into the response function.
Thanks in advance,