Javascript xhr上传在firefox中返回状态0
下面的代码可以在IE和Chrome中使用,但在我尝试的任何firefox版本中都无法使用。在firefox中,我在xhr.onload函数中得到的状态是0,而不是200。Javascript xhr上传在firefox中返回状态0,javascript,firefox,xmlhttprequest,blob,Javascript,Firefox,Xmlhttprequest,Blob,下面的代码可以在IE和Chrome中使用,但在我尝试的任何firefox版本中都无法使用。在firefox中,我在xhr.onload函数中得到的状态是0,而不是200。 同样在firefox中,我得到了Blob{size:9728,键入:“application/xml”},但在chrome中,我得到了Blob{type:“text/plain”,size:9728,slice:function} function fileUpload(idx){ var
同样在firefox中,我得到了Blob{size:9728,键入:“application/xml”},但在chrome中,我得到了Blob{type:“text/plain”,size:9728,slice:function}
function fileUpload(idx){
var xhr = new XMLHttpRequest();
xhr.open('GET', upload_q[q_index_get(idx)], true);
xhr.responseType = 'blob';
var uid = Math.random().toString(34).substr(2);
xhr.onload = function(e) {
console.log('---- this.status ----');
console.log(this.status);
if (this.status == 200) {
var myBlob = this.response;
// myBlob is now the blob that the object URL pointed to.
console.log(myBlob);
var oMyForm = new FormData();
oMyForm.append("uid", uid );
oMyForm.append("fname", upload_fname_q[q_index_get(idx)]);
oMyForm.append("fsize", myBlob.size)
oMyForm.append("q_key", idx)
oMyForm.append("myFile", myBlob);
var oReq = new XMLHttpRequest();
oReq.open("POST", "/client/upload");
oReq.send(oMyForm);
}
};
xhr.send();
return uid;
}
我停止检查status==200,并且上传工作正常。奇怪的是,我是根据我在MDN上读到的内容创建代码的