Copy codeThe 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>