As the best option for getting return data from an ajax call was to use a function. In my case below, I called the function returnData() but how do I get this outside this returnData() function?
var testFile = $("#selection").val(),
testData = getTestData(testFile);
function getTestData(testF) {
$.getJSON("test.php", {
fileTest: testF
}, function (data) {
$.each(data, function (index, value) {
if (value != "") {} else {
testArray[index] = value;
}
});
});
returnData(testArray);
}
By the way, where was testArray defined in the first place? It seems from your code it was already defined outside of
getTestData().Also, the code behind callback will probably be executed before the AJAX function returns:
The above code will almost always fire the alert.
However, to eat cooked noodle, you need to put the
eatNoodle()within the callback like this: