Simple and practical Ajax Development Example tutorial code

Source: Internet
Author: User

aien,i@ruboy.com,1034555083
Ajax (A,B,C,D,E,F,G);
Parameter description: A-request method; B-Request address; C-requested data, A is valid for post; D-callback function, the This reference within the function is a XMLHTTP object; E is asynchronous, unless set to false; f,g-logon username and password

function Ajax (A,B,C,D,E,F,G) {
A = A.touppercase ();
if (e===false) {e=false;} Else{e = true;}
var obj = Ajax.ajax_getobj ();
if (obj) {
if (f) {
Obj.open (A,B,E,F,G);
}else{
Obj.open (a,b,e);
}
if (a.touppercase () = = "Post") {
Obj.setrequestheader ("Content-type", "application/x-www-form-urlencoded");
}
Obj.onreadystatechange=function () {if (typeof D!= "function") {return;} D.apply (Obj,[a,b,c,d,e,f,g]);
Obj.send (c);
}
}
Ajax.ajax_getobj = function () {
var b = null;
if (window.activexobject) {//for ie
var httplist = ["msxml2.xmlhttp.5.0", "msxml2.xmlhttp.4.0", "msxml2.xmlhttp.3.0", "Msxml2.xmlhttp", " Microsoft.XMLHTTP "];
for (var i = httplist.length-1;i >= 0;i--) {
try{
b = new ActiveXObject (httplist[i]);
return b;
}catch (ex) {}
}
}else if (window.xmlhttprequest) {//for other
b = new XMLHttpRequest ();
}
return b;
}

A simpler way to two

Ajax.ajax_getobj = function () {
var b = null;
if (window.activexobject) {//for ie
var httplist = ["msxml2.xmlhttp.5.0", "msxml2.xmlhttp.4.0", "msxml2.xmlhttp.3.0", "Msxml2.xmlhttp", " Microsoft.XMLHTTP "];
for (var i = httplist.length-1;i >= 0;i--) {
try{
b = new ActiveXObject (httplist[i]);
Ajax.ajax_getobj = function () {
return new ActiveXObject (Httplist[i]);
}
return b;
}catch (ex) {}
}
}else if (window.xmlhttprequest) {//for other
b = new XMLHttpRequest ();
}
Ajax.ajax_getobj = function () {
return new XMLHttpRequest ();
}
return b;
}

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.