我并行发送4个POST请求。 Chrome和Firefox等普通浏览器均匀生成上传进程事件。 但IE(在版本10和11上测试)仅在请求完成或中止或上载一半时生成事件。我的代码如下所示:
function XHRUpload(/* ... */) {
//...
this.request = new XMLHttpRequest();
this.request.onreadystatechange = function() {};
this.request.upload.onprogress = function(e) {
console.log(e.loaded, e.total);
};
this.request.onerror = function(e, msg) {
//...
};
this.request.ontimeout = function(e, msg) {
//...
};
this.request.open('POST', this.url, true);
this.request.setRequestHeader('Content-Type', 'text/plain;charset=utf-8');
}
XHRUpload.prototype.upload = function() {
this.request.send(this.options.data);
};
XHRUpload.prototype.abort = function() {
this.request.abort();
};