I was trying to override the getResponseBody
method on XMLHttpRequest object. The code looks so:
xhr.onreadyStateChange = function(){
if (xhr.readyState !== 4) {
return;
}
if (xhr.status === 200) {
// callback to handle the result
} else {
var _orig = xhr.getResponseHeader;
xhr.getResponseHeader = function(name){
return decodeHeader(_orig.apply(xhr,[name]));
};
// callback to handle the failure
}
}
It throws an error "Object doesn't support this property or method" when calling the _orig.apply
.
Any idea? Thanks.
PS: I create a new XHR object every time and do not reuse the old one.