The variable role
gets a new value in every Loop
, when it is inside $.getJSON
it takes the second value of the array and does not change anymore. There are two console.log();
in the code, I put their return next to it. Does anyone know the cause of this and how to get rid of this undesirable scenario?
$(document).ready(function() {
var emails = ["[email protected]", "[email protected]"],
TeamRole = ["founder", "manager"],
hashMail;
for (var i=0 ; i < emails.length ; i++){
hashMail = "http://www.gravatar.com/" + md5(emails[i].toLowerCase().trim()) + ".json?callback=?";
role = TeamRole[i];
console.log(role); // > founder > manager
$.getJSON(hashMail, function (data) {
console.log(role); // > manager > manager
$("#profile-container").append(
"<div>" +
"<img src='" + data.entry[0].thumbnailUrl + "?s=200>" +
"<p>" + data.entry[0].displayName + "</p>" +
"<p>" + self.role + "</p>" +
"<p>" + data.entry[0].aboutMe + "</p>" +
"</div>";
);
});
};
});