2013-02-27 76 views
0

更新內的XMLHttpRequest 2 HTML5進度條:更新HTML5進度條內XMLHTTPRequest.onreadystatechange

for (var i = 0; i < times.value; i++) { 
    xhr.open("POST", uri, false); 
    xhr.send(payload); 
    restSendBar.value += 100/times.value; 
    console.log(i + "th times"); 
} 

xhr.onreadystatechange = function() { 
    if (xhr.readyState === 4 && xhr.status === 200) { 
     restRxBar.value += 100/times.value; 
    } 
}; 

在Firefox中,作爲for循環執行進度條被更新。在Chrome中,進度條在for循環完成後更新。

這是更新進度欄的正確方法嗎?

這是Chrome中的錯誤嗎?

阿倫

回答

0

這可能是因爲Chrome的優先考慮方法調用不同於Firefox瀏覽器。嘗試使用「帶外」更新進度條setTimeout

setTimeout(function() { 
    // Update progress bar here 
    restRxBar.value += 100/times.value; 
}, 0); 
+0

更多的周邊代碼將有所幫助。 我會在哪裏設置這個時間? – 2013-03-01 18:38:54

+0

您將替代您的'restRxBar.value'調用。 – monsur 2013-03-02 02:37:59

+0

仍然沒有變化,進度條在for循環後更新。 – 2013-03-03 12:05:38