我正在使用https://github.com/blueimp/jQuery-File-Upload https://github.com/blueimp/jQuery-File-Upload
它在现代浏览器中使用 XHR 文件上传,在旧 IE 中使用隐藏的 iframe 上传 (8,9)。
当文件验证失败时,服务器返回 4xx 状态代码(错误/失败)。
$('#fileupload').fileupload({
url: url,
dataType: 'json',
done: function (e, data) {
console.log("done")
},
fail: function (e, data) {
console.log("fail")
}
})
然而,在旧IE中,即使我发送 4xx 状态代码,也会调用完成回调。
有没有办法让它调用失败回调(https://github.com/blueimp/jQuery-File-Upload/wiki/Options#fail https://github.com/blueimp/jQuery-File-Upload/wiki/Options#fail)并读取响应正文或状态代码?
我认为它可能需要使用上传文件的隐藏 iframe 方法来做一些事情,但我在文档中找不到任何具体内容。
我应该检查一下经常问的问题 https://github.com/blueimp/jQuery-File-Upload/wiki/Frequently-Asked-Questions#does-the-plugin-support-http-status-codes
// By default, the iFrame Transport handles all responses as success,
// so we override the iFrame to JSON converter to handle error responses:
$.ajaxSetup({
converters: {
'iframe json': function (iframe) {
var result = iframe && $.parseJSON($(iframe[0].body).text());
if (result.error) {
// Handling JSON responses with error property:
// {"error": "Upload failed"}
throw result.error;
}
return result;
}
}
});
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)