I am trying to figure out why I am unable to access data from a JSON object (json.projects[i].projName
) when calling it from within an AJAX function. Below is the code that demonstrates this issue:
var json = JSON.parse(data);
for (var i = 0; i < json.projects.length; i++) {
alert(json.projects[i].projName); // This will display the correct data
$.ajax({
url: epridlist,
method: 'GET'
}).then(function (datas) {
alert(json.projects[i].projName); // This call will fail and report that projName is not known, even though projName exists in the JSON data
});
}
I would appreciate any assistance in understanding this issue. The result displays correctly if I alert the value outside of the AJAX function.