I am looping through an array of urls. Each one fetches some jsonp data from a different domain. The success handler needs to be able to access the data in the original loop, however when called from the callback it is always the last value and not the value that was set when the ajax function was called. How do I access or pass this value to the callback?
for(var site in data.sites){
var domain = data.sites[site].domain;
$('#site-logout').append('<div class="processing" id="' + domain.replace(".","-") + '"><strong>' + domain + '</strong> is logging out.');
$.getJSON(url, function(data){
if(data.success == true)
$("#" + domain.replace(".","-")).removeClass("processing").addClass("processed").html('<strong>' + domain + '</strong> has logged out.');
else
$("#" + site.domain.replace(".","-")).removeClass("processing").addClass("error").text('<strong><a href="http://' + domain + '">' + domain + '</a></strong> has failed to log out. Follow the link to try manually.');
});
}