Using mootools, I have a function that triggers an ajax script to retrieve a value. However, the function seems to return before the AJAX call is completed!
What could be causing this issue...
function getCredits() {
var loadGlobalTab = new Request.JSON({
url: {my api, url removed for security},
evalScripts : true,
async: false, // Tried to prevent the function from returning too soon, but no luck.
onSuccess: function(returnInfo) {
alert(returnInfo.data.total);
return returnInfo.data.total;
}
}).send(sendData); // sendData variable defined earlier
}
The alert displays the correct value, indicating the AJAX call works. However, the function itself does not return anything, suggesting it ends prematurely while the AJAX call is still in progress.
As an experiment, I added return 100
at the end, and the function indeed returned 100.