A case study of native Ajax notation _ajax related

Source: Internet
Author: User

In this paper, we analyze the native Ajax notation. Share to everyone for your reference. The specific analysis is as follows:

Although many JS frameworks now provide Ajax call methods, we do not even have to understand their specific implementation of the principle can be directly invoked, but I do not think from the most basic level to understand a thing, it is difficult to do the best.

var xhr=null; 
if (window. XMLHttpRequest) { 
  //non ie kernel 
  XHR = new XMLHttpRequest (); 
} else if (window. ActiveXObject) { 
  //IE kernel, where earlier versions of IE are written differently, can be queried under 
  XHR = new ActiveXObject ("Microsoft.XMLHTTP"); 
} else { 
  XHR = null; 
} 
 
if (XHR) { 
  xhr.open ("Get", "ajaxserver.action"); 
 
  Xhr.onreadystatechange = function () { 
    ///readystate Value Description 
    //0, initialization, XHR object already created, open 
    //1 not executed, loading, already called Open method , but did not send the request 
    //2, loading completed, request has been sent to complete 
    //3, interactive, can receive some 
 
    data/Status Value Description 
    //200: Success 
    //404: No files, queries or URLs found 
    //500: Server generates internal error 
    if (xhr.readystate = = 4 && Xhr.status = =) {// 
      here can handle the returned content 
      ///generally return JS On or XML data format 
      Console.log (xhr.responsetext); 
      Active release, JS itself will also be recycled 
      XHR = null; 
    } 
  ; 
  Xhr.send (); 
}

I hope this article will help you with your AJAX programming.

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.