I am trying to add/remove data to the projectInfo variable on the success callback. The values don't seem to be sticking.
function getIssues(projectInfo, callback) {
var projectData = projectInfo;
var promises = [];
for (keys = 0; keys < projectData.length; keys++) {
var urlListData = // A url
var result = $.ajax({
url: urlListData,
type: "GET",
async: true,
beforeSend: function (xhr) {
xhr.setRequestHeader("ACCEPT", accept);
},
success: function (xhr, textStatus) {
if (xhr.d.results == "") {
console.log("I am removing this value" + xhr.d.results);
projectData.splice(keys, 1);
keys--;
}
else {
console.log("I add Issues");
console.log("The value of projectData is " + projectData[keys].Issues);
projectData[keys].Issues = xhr.d.results;
console.log("The value of projectData after setting is " + projectData[keys].Issues);
}
},
error: function(xhr, ajaxOptions, thrownError){
projectData.splice(keys, 1);
keys--;
}
})
promises.push(result);
}
$.when.apply(null, promises).done(function () {
console.log("Calling in the when promise");
callback(projectData);
});
}
When I call the getIssues method, I check the console.log values. The log values actually show that Issues are being added and removed then the when promise occurs. However, the value returned from getIssue method doesn't contain any of the added or removed values. What am I doing wrong/missing?