I am trying to create my own version of the ajax method in Jquery to see how it works:
function ajax(url, method) {
var self = this;
this.xhr = new XMLHttpRequest();
this.xhr.onreadystate = function() {
self.xhrHandler();
}
this.xhr.open(method, url, true);
this.xhr.send();
}
ajax.prototype.xhrHandler = function() {
if (this.xhr.readyState == 4) {
console.log(this.xhr.responseText);
}
console.log("test");
}
It never goes into the xhrHandler function, though, since it never prints out "test". What is going on?
Edit: Here is a usage example: var ex = new ajax("www.fake.com/api/item/1/", "GET");