【发布时间】:2011-10-10 07:00:20
【问题描述】:
我正在使用 XHR 上传一个在 FF 中运行良好但在 Chrome 中失败的文件。
抛出一个错误,上面写着Upload failed: 0,这意味着xhr.status 以0 的形式返回——我不确定这是什么意思?没有记录其他状态。
//Check if we have XHR / File support
if (typeof File != "undefined" && typeof (new XMLHttpRequest()).upload != "undefined")
{
var xhr = new XMLHttpRequest();
xhr.upload.onprogress = function(e){
if (e.lengthComputable){
uploadStarted = true;
var loaded = (e.loaded / e.total) * 100;
ShowProgress(loaded);
}
};
xhr.onreadystatechange = function(){
if (xhr.readyState == 4){
if (xhr.status == 200){
uploadComplete();
} else {
alert("Upload failed: " + xhr.status);
}
console.log("status",xhr.status);
}
};
var formElement = document.getElementById("configForm");
xhr.open("POST", $("#configForm").attr('action') , true);
xhr.send(new FormData(formElement));
}
【问题讨论】:
标签: javascript html file-upload xmlhttprequest