0
我想有一個函數,返回 jQuery.ajax()調用的repsonseText。我見過的所有例子都說使用「成功」函數來處理返回的數據。但是,對於我實現我需要類似以下內容:需要jQuery.ajax的responseText返回,而不是使用「成功」函數
function getRemoteValue(id) {
var request = jQuery.ajax({
url:'somefile.php',
dataType:'text'
});
return request.responseText;
}
當我對這個函數的調用,螢火蟲顯示請求與返回正確的響應經歷。然而,當我嘗試以下方法,我只能得到一個空字符串:
var some_value = getRemoteValue(1); // The problem is here. some_value is empty.
jQuery('.someclass').html(some_value);
// Other processing using some_value;
再次,對於我的實現,我不能做jQuery的HTML(SOME_VALUE);(」 SomeClass的。)。在ajax()調用中。我怎樣才能得到responseText返回?謝謝!
我想檢查一下http://stackoverflow.com/questions/3732258/why-can-i-not-return-responsetext-from-an-ajax-function – 2010-12-10 21:19:12
感謝您的鏈接。整個「異步」起初並沒有陷入困境:) – robertwbradford 2010-12-20 18:57:30