How to keep jQuery jqXHR.responseJSON with own converters?

China☆狼群 提交于 2020-01-06 07:06:24

问题


For jQuery 3.2.1 I've responseJSON in ajax errors

$(document).ajaxError(function (event, jqXHR, options, jsExc) {
    alert(jqXHR.responseJSON);
})

But when I've added custom converter

$.ajaxSetup({
    converters: {
        "text json": function (stringData) {
            var json = JSON.parse(stringData);
            ... // some modification
            return json;
        });
    }
});

jqXHR.responseJSON become undefined (butjqXHR.responseText present). So with converters jQuery doesn't evaluate jqXHR.responseJSON = JSON.parse(jqXHR.responseText). Is it possible to force them to do this in order to get jqXHR.responseJSON in ajaxError callback when converters configured?

BTW: according jquery ajax does not parse json on failure in case error jQuery doesn't convert responseText to responseJSON, but without converters in my case it does.

来源:https://stackoverflow.com/questions/48229776/how-to-keep-jquery-jqxhr-responsejson-with-own-converters

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