Ajax Request Class _ajax related

Source: Internet
Author: User
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>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.