Get mode
1 //Create a XMLHttpRequest object that uses ActiveX objects for older versions of Internet Explorer (IE5 and IE6) to consider compatibility issues2 varAjax = window. XMLHttpRequest?NewXMLHttpRequest ():NewActiveXObject ("Microsoft.XMLHTTP");3 4 //sets the type of request, the server URL, and whether to process asynchronously5Ajax.open ("Get", "test.ashx?name=jcx&id=" +NewDate (),true);6 7Ajax.onreadystatechange=function()8 {9 //4: The request is complete and the response is readyTen if(ajax.readystate==4) One { A //200: Success - if(ajax.status==200) - { the //Processing Results - alert (ajax.responsetext); -}Else - { +Alert ("The AJAX server returned an error! "); - } + } A at } - - //send a request to the server -Ajax.send ();
Post mode
1 varAjax=window. XMLHttpRequest?NewXMLHttpRequest ():NewActiveXObject ("Microsoft.XMLHTTP");2 3Ajax.open ("Post", "Test.ashx",true);4 5Ajax.onreadystatechange =function () {6 if(ajax.readystate==4)7 {8 if(ajax.status==200) {9 alert (ajax.responsetext);Ten } One } A } - -Ajax.setrequestheader ("Content-type", "application/x-www-form-urlencoded"); theAjax.send ("name=jcx&id=23");
Create a XMLHttpRequest object that uses ActiveX objects for older versions of Internet Explorer (IE5 and IE6) to consider compatibility issues
var ajax = window. XMLHttpRequest? New XMLHttpRequest (): New ActiveXObject ("Microsoft.XMLHTTP");
Sets the type of request, the server URL, and whether to process asynchronously
Ajax.open ("Get", "test.ashx?name=jcx&id=" +new Date (), true);
Ajax.onreadystatechange=function ()
{
4: The request is complete and the response is ready
if (ajax.readystate==4)
{
200: Success
if (ajax.status==200)
{
Processing results
alert (Ajax.responsetext);
}else
{
Alert ("The AJAX server returned an error! ");
}
}
}
Send a request to the server
Ajax.send ();
Ajax native JavaScript notation