function lookupRemote(searchTerm)
{
var defaultReturnValue = 1010;
var returnValue = defaultReturnValue;
$.getJSON(remote, function(data)
{
if (data != null)
{
$.each(data.items, function(i, item)
{
returnValue = item.libraryOfCongressNumber;
});
}
});
return returnValue;
}
爲什麼returnValue
這個函數總是等於在函數開頭設置的默認值,而不是從JSON查找檢索的值?
請參閱http://stackoverflow.com/questions/3537434/cant-get-correct-return-value-from-an-jquery-ajax-call – 2010-11-17 02:55:39
可能的重複[如何從AJAX調用返回響應? ](http://stackoverflow.com/questions/14220321/how-to-return-the-response-from-an-ajax-call) – Bergi 2014-04-30 21:22:06