Implementing Ajax with Pure XMLHttpRequest

Source: Internet
Author: User

1 <!DOCTYPE HTML>2 <HTMLxmlns= "http://www.w3.org/1999/xhtml">3 <Head>4     <Metahttp-equiv= "Content-type"content= "text/html; charset=utf-8" />5     <title></title>6     <Scripttype= "Text/javascript">7         /**8 * Create XMLHttpRequest Objects9         */Ten         functioncreatexhr () { One             varXHR= NULL; A             if(window. XMLHttpRequest) { - XHR= NewXMLHttpRequest (); -             } the             Else { - XHR= NewActiveXObject ("Microsoft.XMLHTTP"); -             } -             returnxhr; +         } -  +         functiontestxhr () { A             varXHR=createxhr (); at Window.alert (XHR); -         } -  -         functiongetservertest () { -             //Get XHR Object -             varXHR=createxhr (); in             //Create request - Xhr.open ("Get", "ajax.ashx", true); to             //Setting the callback function + Xhr.onreadystatechange= function () { -                 if(Xhr.readystate== 4 &&Xhr.status==  $) { the                     //the server has processed the request and correctly responded to the data to the client *                     varResText=Xhr.responsetext; $ document.getElementById ("hh"). InnerText=ResText;Panax Notoginseng                 } -             } the             //4. Sending the request + Xhr.send (NULL); A         } the     </Script> + </Head> - <Body> $     <inputtype= "button"value= "Test Xhr"onclick= "testxhr ()"> $     <H2ID= "hh"></H2> -     <ahref= "Javascript:getservertest ()">Submit data</a> - </Body> the </HTML>

Implementing Ajax with Pure XMLHttpRequest

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.