问题
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