我正在開發應用程序,它將獲得一些與我的問題無關的動態內容。問題是jquery - 在變量中迷失的範圍
var pat;
$.post('venki/path.jsp', { nam:nam } , function(data) {
pat=data;
alert(pat); //it will displayed the received code form path.jsp
});
alert(pat);// it will not keep the data received from path.jsp
現在我需要不失去範圍。
例如:
var pat=0;
$.post(
pat = 1
);
alert(pat);
應該提醒1,而不是Ø
在java中,我應該用靜態的。在jQuery中,如何聲明靜態變量。
得到了一個答案: 它簡單而且非常有用,無需擔心同步。答案是棘手...
的另一個副本【如何返回從AJAX調用的響應?](http://stackoverflow.com/questions/14220321/how-以回報從一個阿賈克斯迴應) – Quentin
這與範圍和一切有關時間無關。異步JavaScript和XML是**異步** – Quentin