I am writing a Javascript Library which has the following code:
Constructor (Creating intial keys and creating a XMLHTTP Request object):
function hrce(key) {
var about = {
Version: 0.1,
Author: "AAA",
Created: "Spring 2014",
Updated: "March 2014"
};
if (key) {
this.xhr = "";
this.xhrdata = "";
this.xhrmethod = "";
this.xhrurl = "";
this.xhrquery = "";
//init with the current avaliable information
this.key = key;
this.protocol = "http:" === document.location.protocol ? "http://" : "https://";
if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
this.xhr = new XMLHttpRequest();
}
else {// code for IE6, IE5
this.xhr = new ActiveXObject("Microsoft.XMLHTTP");
}
return this;
} else {
// No 'id' parameter was given, return the 'about' object
return about;
}
};
Here are my Library functions:
hrce.prototype = {
load: function() {
if (this.xhr && this.xhr != "" && this.key && this.key != "") {
this.xhrdata = [{"access_key": this.key}];
this.xhrurl = this.protocol + "localhost/hrce/v1/action/hsio/";
this.xhr.onreadystatechange = this.initilizer();
this.xhr.open("POST", this.xhrurl, true);
this.xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
this.xhrquery = "access_key=" + this.key;
this.xhr.send(this.xhrquery);
}
return this;
},
initilizer: function() {
if (this.xhr.readyState == 4 && this.xhr.status == 200)
{
console.log(this.xhr.responseText);
}
}
};
now if i call for example: hrce("f07c7156").load();
Ajax call goes successfully but its not calling my this.xhr.onreadystatechange = this.initilizer();
call in load prototype function. Whats wrong in it?