LithMaster
11-10-2007, 03:14 AM
Hi all, I wanted to learn AJAX so I have made a little object to make my life easier, unfortunately, It doesn't do anything at all... I'm sure I'm missing something
function Ajax ( Location , Method , RequestDone , Refresh) {
this.Conn = null;
this.Method = Method;
this.TimeLeft = '';
this.TimerID = '';
this.Data = '';
this.RequestDone = RequestDone;
this.Handler = function () {
this.OnTimeOut();
};
try {
// Modern Browsers - Firefox, Opera 8.0+, Safari
this.Conn=new XMLHttpRequest();
}
catch (e) {
try {
// New IEs
this.Conn = new ActiveXObject( "Msxml2.XMLHTTP" );
}
catch (e) {
try {
// Old IEs
this.Conn = new ActiveXObject( "Microsoft.XMLHTTP" );
}
catch (e) {
alert( "Your browser does not support AJAX!" );
return false;
}
}
}
this.Conn.open( this.Method , this.Location , true );
this.Conn.onreadystatechange = function() {
if( this.Conn.readyState == 4 ) {
if ( this.Conn.status == 200 ) {
var Response = '';
if ( this.Conn.responseText ) {
Response = this.Conn.responseText;
}
if ( this.Conn.responseXml ) {
Response = this.Conn.responseXml;
}
this.RequestDone( Response );
};
}
}
this.SendRequest = function ( Data ) {
this.Data = Data;
this.Conn.send ( Data , true );
};
}
Connection = new Ajax ( 'test.php' , "GET" , Handle);
Connection.SendRequest();
function Handle( Response ) {
alert ( Response );
};
I also have a Test page-
Connection = new Ajax ( 'test.php' , "GET" , Handle);
Connection.SendRequest();
function Handle( Response ) {
alert ( Response );
};
test.php writes "Hi!"
thanks in advance
function Ajax ( Location , Method , RequestDone , Refresh) {
this.Conn = null;
this.Method = Method;
this.TimeLeft = '';
this.TimerID = '';
this.Data = '';
this.RequestDone = RequestDone;
this.Handler = function () {
this.OnTimeOut();
};
try {
// Modern Browsers - Firefox, Opera 8.0+, Safari
this.Conn=new XMLHttpRequest();
}
catch (e) {
try {
// New IEs
this.Conn = new ActiveXObject( "Msxml2.XMLHTTP" );
}
catch (e) {
try {
// Old IEs
this.Conn = new ActiveXObject( "Microsoft.XMLHTTP" );
}
catch (e) {
alert( "Your browser does not support AJAX!" );
return false;
}
}
}
this.Conn.open( this.Method , this.Location , true );
this.Conn.onreadystatechange = function() {
if( this.Conn.readyState == 4 ) {
if ( this.Conn.status == 200 ) {
var Response = '';
if ( this.Conn.responseText ) {
Response = this.Conn.responseText;
}
if ( this.Conn.responseXml ) {
Response = this.Conn.responseXml;
}
this.RequestDone( Response );
};
}
}
this.SendRequest = function ( Data ) {
this.Data = Data;
this.Conn.send ( Data , true );
};
}
Connection = new Ajax ( 'test.php' , "GET" , Handle);
Connection.SendRequest();
function Handle( Response ) {
alert ( Response );
};
I also have a Test page-
Connection = new Ajax ( 'test.php' , "GET" , Handle);
Connection.SendRequest();
function Handle( Response ) {
alert ( Response );
};
test.php writes "Hi!"
thanks in advance