Im trying to use jQuery.ajaxPrefilter API to make a HTTP Ajax interceptor.
Here is the jsFiddle
As you can see, I have access to the jqXHR object in the prefilter function, I can even console.log the entire jqXHR object, but some attributes, like responseJSON is returning undefined when pointing at them directly. This is the attribute I will like to modify in order to accomplish the HTTP interceptor.
Any ideas on why I cant access jqXHR.responseJSON attribute?
Here is the snippet of the code that is running on jsFiddle
var data = {
'msg': 'hey!'
};
$.ajaxPrefilter(function( options, originalOptions, jqXHR ) {
console.log(jqXHR); --> Returns the entire jqXHR object
console.log(Object.isSealed(jqXHR)); --> return false
console.log(Object.isFrozen(jqXHR)); --> return false
console.log(jqXHR.responseJSON); --> return undefined
});
$.ajax({
type: 'POST',
url: '/echo/json/',
cache: false,
data: {
json: JSON.stringify(data),
delay: 0
}
}).done(function (data) {
document.getElementById('msg').innerHTML = data.msg;
});
The rest of the code is working as intended, you can check it out on my fiddle.