这里是最初的代码: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调用后所需的值?