Reputation: 513
One AJAX Request works but when I add a second one it doesn't.
Working code (returns 'wins: 3' as expected)
function GetMissingData(data, myID)
{
$.when(AJAXf1(myID, '4')).done(
function(a1)
{
console.log("wins: "+a1[0].DATA);
}
);
}
function AJAXf1(myID, val)
{
return $.ajax({
url: "./PHP/ajaxRequests.php",
dataType: "json",
data :
{
'moreData' : myID,
'res' : val
}
})
}
and this doesn't, variable is now undefined ('wins: undefined'):
function GetMissingData(data, myID)
{
$.when(AJAXf1(myID, '4'), AJAXf1(myID, '4')).done(
function(a1, a2)
{
console.log("wins: "+a1[0].DATA);
}
);
}
function AJAXf1(myID, val)
{
return $.ajax({
url: "./PHP/ajaxRequests.php",
dataType: "json",
data :
{
'moreData' : myID,
'res' : val
}
})
}
(yes, I'm calling same function, I was testing. In the future, I will change one of the parameters of the function)
Thanks
Upvotes: 0
Views: 53
Reputation: 910
In your first example you got an ajax response directly as a single JS object. In the second one you got an array of JS objects (something like [Object, "success", Object]). And I think you just can't use the same code on different structures.
Upvotes: 1