CopyCode The Code is as follows: // Ajax class
Function ajaxrequest (){
VaR xmlobj = false;
VaR cbfunc, objself;
Objself = this;
Try {xmlobj = new XMLHttpRequest ;}
Catch (e ){
Try {xmlobj = new activexobject ("msxml2.xmlhttp ");}
Catch (E2 ){
Try {xmlobj = new activexobject ("Microsoft. XMLHTTP ");}
Catch (E3) {xmlobj = false ;}
}
}
If (! Xmlobj) return false;
This. method = "Post ";
This. url;
This. async = true;
This. content = "";
This. Callback = function (cbobj) {return ;}
This. Send = function (){
If (! This. Method |! This. url |! This. async) return false;
Xmlobj. Open (this. method, this. url, this. async );
If (this. Method = "Post") xmlobj. setRequestHeader ("Content-Type", "application/X-WWW-form-urlencoded ");
Xmlobj. onreadystatechange = function (){
If (xmlobj. readystate = 4 ){
If (xmlobj. Status = 200 ){
Objself. Callback (xmlobj );
}
}
}
If (this. Method = "Post") xmlobj. Send (this. content );
Else xmlobj. Send (null );
}
}
Ajax request class
By hotheart)
Site: http://www.xujiwei.cn/
Blog: http://www.xujiwei.cn/blog/
Class Name: Ajax
Creation Method: var ajaxobj = new Ajax;. If creation fails, false is returned.
Attribute: method-Request Method, String, post, or get. The default value is post.
URL-request URL, String, empty by default
Async-asynchronous or not. True indicates asynchronous, and false indicates synchronous. The default value is true.
Content-the content of the request. If the request method is post, this attribute must be set. The default value is null.
The callback-callback function is the function called when the response content is returned. The default value is direct return. The callback function has a parameter XMLHTTPRequest object, that is, the callback function must be defined as follows: function mycallback (xmlobj)
Method: Send ()-Send request, no Parameter
Example:
<SCRIPT type = "text/JavaScript" src = "ajaxrequest. js"> </SCRIPT>
<SCRIPT type = "text/JavaScript">
VaR ajaxobj = new ajaxrequest; // create an Ajax object
Ajaxobj. method = "get"; // set the request method to get
Ajaxobj. url = "Default. asp" // The URL is default. asp.
// Set the callback function to output the response content
Ajaxobj. Callback = function (xmlobj ){
Document. Write (xmlobj. responsetext );
}
Ajaxobj. Send (); // send the request
</SCRIPT>