Ajax native JavaScript notation

Source: Internet
Author: User

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

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.