html5 xhr,Chrome中通过XHR上传HTML5失败

该博客讨论了一位开发者遇到的问题,即使用XHR进行文件上传在Firefox上正常工作,但在Chrome中失败,错误提示为'Upload failed: 0'。开发者检查了xhr.status,发现其返回值为0,这表明请求未完成。博客内容涉及了如何处理这个问题,并探讨了可能的解决策略。
摘要由CSDN通过智能技术生成

I am using XHR to upload a file which works great in FF but fails in Chrome.

An error is thrown which says Upload failed: 0 which means that xhr.status comes back as 0 - I'm not sure what this means? No other status is recorded.

//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));

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值