Prototype was used for projects some time ago. JS later found some complicated situations, sometimes with memory overflow, and simply needed it. To ensure program compatibility, it implemented a simple Ajax encapsulation based on the prototype interface, firefox is not tested. the number of lines to be compressed is not formatted.
<HTML>
<Head>
<SCRIPT>
VaR syj = {};
// Method for sending an Ajax request
Syj. Ajax = function (URL, OBJ ){
VaR httprequest;
If (window. activexobject) Try {httprequest = new activexobject ("Microsoft. XMLHTTP ");} catch (e) {try {httprequest = new activexobject (" msxml2.xmlhttp ");} catch (e ){}}
If (! Httprequest) {alert ('cannot create XMLHTTP instance'); obj. oncomplete ();}
Httprequest. onreadystatechange = function () {If (httprequest. readystate = 4) {OBJ ['oncomplete'] (httprequest );}}
If (URL. indexof ('machinedate') =-1) URL + = (URL. indexof ('? ') =-1? "? ":" & ") + (" Machinedate = "+ new date (). gettime ());
URL + = (URL. indexof ('? ') =-1? "? ":" & ") + Obj. parameters;
If (obj. asynchronous = true) httprequest. Open (obj. method, URL); else httprequest. Open (obj. method, URL, false );
Httprequest. Send (null );
Return httprequest;
};
Function Test (){
Alert ("Test start ");
VaR url = "http://www.baidu.com /";
Syj. Ajax (URL ,{
Method: "Get ",
Parameters: "s? WD = csdn ",
Asynchronous: True,
Onfailure: function (httprequest ){
Alert ("error! ");
},
Oncomplete: function (httprequest ){
If (httprequest. Status = 200 ){
Alert (httprequest. responsetext );
}
}
}
);
Alert ("test end ");
}
</SCRIPT>
</Head>
<Body>
<Input type = "button" onclick = "test ()" value = "test"/>
</Body>
</Html>