Copy Code code as follows:
Ajax classes
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 (blood-hearted)
site:http://www.xujiwei.cn/
blog:http://www.xujiwei.cn/blog/
Class name: Ajax
Creation method: Var ajaxobj=new AJAX; False
Property:method - If the creation fails Request method, String, post or get, default to post
url - request URL, string, default null
async - is asynchronous, true is asynchronous, false is synchronous, default is true
content- What is requested, if the request method is post need to set this property, The default is an empty
callback -callback function, that is, the function that is called when the response content is returned, the default is to return directly, and the callback function has a parameter of XMLHttpRequest object, that is, when defining a callback function: function Mycallback ( Xmlobj)
Method: Send () - sending request, no parameters
An example:
<script type= "Text/javascript" src= "Ajaxrequest.js" ></script>
<script type= "Text/javascript"
var ajaxobj=new ajaxrequest; //Creating Ajax Objects
Ajaxobj.method= "Get"; //Set request mode for Get
Ajaxobj.url= "Default.asp" //URL for default.asp
//Set callback function, Output response content
Ajaxobj.callback=function (xmlobj) {
document.write (xmlobj.responsetext);
}
Ajaxobj.send (); //Send request
</script>