2013-02-27 75 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