Here are 3 methods which handle my ajax calls.
I loop until pass b.c. I've had problems with the Ajax Object working as expected. This is noted here
/**
* Ajax
*/
var Ajax = ( function ()
{
var Ajax = function (element)
{
this.object = this.create();
};
Ajax.prototype.create = function()
{
var request;
try
{
request = new window.XMLHttpRequest();
}
catch( error )
{
try
{
request = new window.ActiveXObject( "Msxml2.XMLHTTP" );
}
catch( error )
{
try
{
request = new window.ActiveXObject( "Microsoft.XMLHTTP" );
}
catch( error )
{
request = false;
}
}
}
return request;
};
Ajax.prototype.use = function( param, ajax_func )
{
var GATEWAY = 'class.ControlEntry.php';
var self = this;
this.object.open( "POST", GATEWAY, true );
this.object.setRequestHeader( "Content-type", "application/x-www-form-urlencoded" );
this.object.setRequestHeader( "Content-length", param.length );
this.object.setRequestHeader( "Connection", "close" );
this.object.onreadystatechange = function()
{
if( this.readyState === 4 )
{
if( this.status === 200 )
{
ajax_func( this.responseText );
return true;
}
else
{
self.invoke( param, ajax_func );
return false;
}
}
};
this.object.send( param );
return true;
};
Ajax.prototype.invoke = function( param, ajax_func )
{
var state = false,
count = 1;
while( state === false && count <= 5 )
{
if( count !== 1 )
{
alert( 'Ajax Object Use Failed | Try Again ');
}
state = this.use( param, ajax_func );
count++;
}
return state;
};
return Ajax;
} () );