0
我有问题从返回ajax回调函数里面的另一个函数返回数组。问题是在第一个周期内没有收到阵列数据.....在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
}
但警报试验(与返回)始终显示数组的内容连第一次,所以我不理解你的观点。 –
更新了对你所看到的解释。 – slashingweapon
感谢解决方案.. –