我在从另一个函数内部的返回 ajax 回调函数中获取返回的数组时遇到问题。问题是在第一个周期内没有接收到数组数据.....
var testFile = $("#selection").val();
var testData = getTestData(testFile);
alert(testData); // not working during the first time I run the function, empty
function getTestData(testF)
{
var testArray = [];
$.getJSON("test.php",{fileTest: testF}, function(data)
{
$.each(data, function(index, value)
{
if(value == "")
{
}else
{
testArray[index] = value;
}
}
});
alert(testArray); // working I see the values
return testArray; // not working the first time running this function
}