jQuery file upload plugin - fail callback not firing in IE < 10

会有一股神秘感。 提交于 2020-01-03 17:06:53

问题


I am using the https://github.com/blueimp/jQuery-File-Upload

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

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")
    }
})

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?

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.


回答1:


I should have checked the Frequently Asked Questions

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


来源:https://stackoverflow.com/questions/21176964/jquery-file-upload-plugin-fail-callback-not-firing-in-ie-10

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!