This article mainly introduces its own implementation of AJAX encapsulation examples, need friends can refer to the following
The code is as follows: //javascript object:ajax Object//created by Rexlee function Ajax (url,data) { this.url=url; &nb Sp This.data=data; this.browser= (function () { -if (Navigator.userAgent.indexOf ("MSIE") >0 { return "MSIE";//ie browser }else{ &NBSP ; return "others";/Other }} (); }; ajax.prototype={ Get:function () { var result; VAR xml http if (this.browser== ' Msie ') { try{ xmlhttp=new activexobject (' microsoft.xmlhttp '); }catch (e) { xmlhttp=new ActiveXObject (' msxml2.xmlhttp ');   }else{ & nbsp xmlhttp=new XMLHttpRequest (); }; xmlhttp.onreadystatechange=function () { result = XMLH ttp.responsetext;//closures, cannot use this. Attribute }; Xmlhttp.open (' Get ', this.url+ '? ') +this.data,false);//true cannot crawl data, why? xmlhttp.send (null); return result; }, post:function () { var result; var xm Lhttp; if (this.browser== ' Msie ') { xmlhttp=new ActiveXObject ( ' Microsoft.XMLHTTP '); }else{ Xmlhttp=new XMLHT TpRequest (); }; xmlhttp.onreadystatechange=function () { result = XMLH ttp.responsetext;//closures, cannot use this. Attribute }; Xmlhttp.open (' POST ', this.url,false);//Must be set to false, otherwise unable to crawl responsetext Xmlhttp.setrequestheader ("Content-type", "application/x-www-form-urlencoded");//post, this must be Xmlhttp.send (this.data); return result; }}; //var a=new Ajax (' Opp2.js ', '); Alert (' by Getn ' +a.get ())//alert (' by Postn ' +a.post ()); Window.onload=function () {document.getElementById ("btn"). Onclick=function () { var P=document.getelementbyid ("T"). Value var a=new Ajax ("phpoop/ Getpage.php "," page= "+p); document.getElementById ("box"). Innerhtml=a.get (); }; }