jQuery文件上传插件 - 10 [英] jQuery file upload plugin - fail callback not firing in IE < 10

查看:137
本文介绍了jQuery文件上传插件 - 10的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 https://github.com/blueimp/jQuery-File-Upload

它使用在现代浏览器中的XHR文件上传和oldIE中的隐藏iframe上传(8,9)。

It uses XHR file uploads in modern browser and hidden iframe uploads in oldIEs (8,9).

当文件验证失败时,服务器返回4xx状态代码(错误/失败)。

The server returns a 4xx status code (error/fail), when file validation failed.

$('#fileupload').fileupload({
    url: url,
    dataType: 'json',
    done: function (e, data) {
       console.log("done")
    },
    fail: function (e, data) {
       console.log("fail")
    }
})

但是在oldIE中,即使我发送4xx状态码,也会调用done回调。
是否有一种方法可以调用失败回调( https ://github.com/blueimp/jQuery-File-Upload/wiki/Options#fail )并读取响应正文或状态码?

However in oldIEs the done callback is called even when I send a 4xx status code. Is there a way to make it call the fail callback (https://github.com/blueimp/jQuery-File-Upload/wiki/Options#fail) and read the response body or statuscode?

我认为它可能需要做一些与隐藏的iframe方法上传的文件,但我找不到任何具体的文档。

I think it might have to do something with the hidden iframe method of uploading the files but I couldn't find anything specific in the docs.

推荐答案

我应该检查常见问题

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

这篇关于jQuery文件上传插件 - 10的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆