Examples of native AJAX writing and ajax instance analysis

Source: Internet
Author: User

Examples of native AJAX writing and ajax instance analysis

This article analyzes the native AJAX writing method. Share it with you for your reference. The specific analysis is as follows:

Although many JS frameworks now provide AJAX call methods, we can directly call them without having to know the specific implementation principles, however, I think it is difficult to do the best without learning about one thing at the basic level.

Var XHR = null; if (window. XMLHttpRequest) {// non-IE kernel XHR = new XMLHttpRequest ();} else if (window. activeXObject) {// IE kernel. The earlier IE versions are written differently. For details, see 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 created, open // 1 not executed, load, open method called, but no request has been sent // 2, the load is complete, the request has been sent // 3, interaction, some data can be received // status description // 200: success // 404: No file, query, or URl found // 500: the server generates an internal error if (XHR. readyState = 4 & XHR. status = 200) {// The returned content can be processed here // The console is generally returned in JSON or XML data format. log (XHR. responseText); // actively released. JS will also recycle XHR = null ;}}; XHR. send ();}

I hope this article will help you with 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.