Trying to implement own AJAX prototype and not using jQuery or other one. I can't retrieve any result, breakpoint, which is set on some line doesn't fire:
The problem is with the next part:
Why is it undefined, if I have previously init the HttpXml
instance with the init()
function:
I'm trying to send a request from other part of program doing the next:
var ajaxInstance = new GC3D.Ajax();
ajaxInstance.init();
var response = ajaxInstance.sendRequest({
HttpMethod: 'GET',
UrlEndpoint: '/SomeService?function=someFunctionName'
});
Full source of that prototype:
GC3D.Ajax = function() {
this.httpRequest = undefined;
this.listExceptions = undefined;
};
GC3D.Ajax.prototype.init = function() {
this.listExceptions = [];
if ( window.XMLHttpRequest ) this.httpRequest = new XMLHttpRequest();
else if ( window.ActiveXObject ) {
try {
this.httpRequest = new ActiveXObject( 'Microsoft.XMLHTTP' );
}
catch ( exception ) {
this.listExceptions.push( exception );
try {
this.httpRequest = new ActiveXObject( 'Msxml2.XMLHTTP' );
}
catch ( exception ) {
this.listExceptions.push( exception );
try {
this.httpRequest = new ActiveXObject( 'Microsoft.XMLHTTP' );
}
catch ( exception ) {
this.listExceptions.push( exception );
}
}
}
}
if ( !this.httpRequest ) {
console.error( 'Can\'t create a HTTP Request instance for AJAX! Possible problems:' );
console.error( this.listExceptions );
}
else this.httpRequest.onreadystatechange = this.getContentFromRequest;
};
GC3D.Ajax.prototype.sendRequest = function( properties ) {
if ( this.httpRequest !== undefined ) {
this.httpRequest.open( properties.HttpMethod, properties.UrlEndpoint );
this.httpRequest.send();
}
else throw 'HTTP Request instance isn\'t defined!';
};
GC3D.Ajax.prototype.getContentFromRequest = function() {
if ( this.httpRequest !== undefined ) {
if ( this.httpRequest.readyState === 4) {
if ( this.httpRequest.status === 200 ) return this.httpRequest.responseText;
else console.log( 'There was a problem with the request in GC3D.Ajax.' );
}
}
};
GC3D.Ajax.prototype.get = function() {
return this.httpRequest;
};
What's incorrect and why it isn't firing at that line above?
Thanks