我剛剛注意到安裝Firefox 11後,我在webapp上發現了一些奇怪的行爲。我之前沒有看到過這個錯誤,並且該站點已經運行了一年多。發送函數完成之前是否可以回調完成的XmlHttpRequest觸發器?
var timeOutTimer = null;
var StartDownload = function() {
xhr.open("GET", "/Download", true); //Notice asynchronous=true
xhr.onreadystatechange = DownloadComplete;
xhr.send("...");
timeOutTimer = new Timer(......); //This line gets executed AFTER DownloadComplete()
};
var DownloadComplete = function() {
if (xhr.readyState == 4) {
timeOutTimer.Abort(); //<--------timeOutTimer is null here
//Callstack points back to xhr.send
}
}
如果真的有可能爲XMLHttpRequest來甚至退出的send()之前調用onreadystatechange的回調 - 功能?
只有當我在本地開發服務器上瀏覽網站時纔會出現此錯誤。另外,如果我添加1sec延遲serverside沒有問題。我還沒有嘗試過任何其他瀏覽器。
我想解決方案是在發送之前啓動定時器,但我只想知道這種行爲背後的原因,以及它是否正確,因爲我從來沒有經歷過它。
您是否重新初始化現有的XHR對象,或者在每次調用StartDownload時創建一個新對象?你的代碼中有沒有'alert()'調用? – 2012-03-19 02:55:06