Ajax JavaScript Learning Summary

Source: Internet
Author: User

Ajax, is the asynchronous request, specifically want to update a part of the page, no need to reload the entire page, as long as the sending request to update the local page.

Ajax, not new language, just a technology

The use of Ajax relies on XMLHttpRequest objects, and the "members" commonly used in objects include: Open, Send,responsetext,onreadystatechange

Create Xhr object: var xmlrequest = new XMLHttpRequest ();

xhr Send request: Xmlrequest.open ("method", "url", True/false);

Xmlrequest.send ([string]);

parameters in open:

    1. Method:get/post, and select one to indicate the method used when sending
    2. URL: The location of the file on the server, or the path
    3. The third argument, if true, is asynchronous, and vice versa is synchronous

parameters in Send:

1. String can only be used when the POST request, the GET request to transfer more content to add in the URL

XHR Response: When transmitting a string, use: responsetext eg:var tmptext = Xmlrequest.responsetext;

The transport XML format is, using: responsexml eg:var tmpxml = xmlrequest.responsexml;

onReadyStateChange: Use this to store the function to be executed when the data is returned; Here are two volumes: one is readyState and the other is status. Whenever the value of readystate changes, it is called

onReadyStateChange this function.

value of readystate:0-Request not initialized

The server connection has been established

2-Request received

3-In Request processing

4-The request is complete and the response is ready

Status value:"404": Page not Found

"$": OK

Examples from the world-class:

Xmlhttp.onreadystatechange=function () {      if (xmlhttp.readystatexmlhttp.status==200)        {            document.getElementById ("mydiv"). innerhtml=xmlhttp.responsetext;        } }

Use a callback function instead of onreadystatechange, written like this:

function Loadxmldoc () {.... AJAX script goes here ...} </script>

function MyFunction () { Loadxmldoc ("Ajax_info.txt", function () { if (xmlhttp.readystate==4 && xmlhttp.status==200) { document.getElementById ("mydiv"). Innerhtml=xmlhttp.responsetext; } );}

  

Ajax JavaScript Learning Summary

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.