Ajax class in Javascript not working
<p>I am trying to create my own version of the ajax method in Jquery to see how it works:</p>

<pre><code>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");
}
</code></pre>

<p>It never goes into the xhrHandler function, though, since it never prints out "test". What is going on?</p>

<p>Edit: Here is a usage example: <code>var ex = new ajax("www.fake.com/api/item/1/", "GET");</code></p>
