Is it possible to send an ajax request, and intercept or see the HTML response code and then act upon it? I have a system that uses plain JS and XMLHttpRequest to see things like abort, error, and timeout, but it would be far more useful to track 404s and 409s etc.
This is my current code which is quite popular for this method
(function(open) {
XMLHttpRequest.prototype.open = function(method, url, async, user, pass) {
this.addEventListener("abort", function() {
self.trigger('abort');
}, false);
this.addEventListener("error", function() {
self.trigger('error');
}, false);
this.addEventListener("timeout", function() {
self.trigger('timeout');
}, false);
this.addEventListener("load", function() {
self.trigger('load');
}, false);
open.call(this, method, url, async, user, pass);
};
})(XMLHttpRequest.prototype.open);
But I am looking to switch on HTTP response codes. I also am tied into jQuery so I can use whatever jQuery setup options provide, but so far I haven't seen a way to get response codes.
Please note I am looking for a global solution. I cannot be adding 100s of individual function calls per individual ajax request.