這裏是最初的代碼:jQuery的阿賈克斯獲得導致
var res = null;
$.post('test.php', 'q=testdata', function(response) {
res = response;
});
我需要在我的代碼,或Ajax調用後立即在某些時候使用res
。我嘗試這樣做:
var res = null;
$.post('test.php', 'q=testdata', function(response) {
res = response;
alert('Note 1: '+res); /* Returned exactly what I wanted */
});
alert('Note 2: '+res); /* Returned null. I need to use res here. How? */
怎麼可能使用res
保持Ajax調用後所需的值?