Home How to keep jQuery jqXHR.responseJSON with own converters?
Reply: 0

How to keep jQuery jqXHR.responseJSON with own converters?

user1037
1#
user1037 Published in April 22, 2018, 4:54 am

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.

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.296909 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO