Beginners must read native ajax-asynchronous JavaScript and XML

Source: Internet
Author: User

1. Front Page

<form action= "#" method= "POST" >

Name <input type= "text" name= "first" id= "first"/>

<span id= "Show" ></span>

</form>

action= "#" is submitted to this page

2. Add Ajax code to the head tag element

In fact, this AJAX function is the check (str) function

The function is to pass in a string hello to the background server, the background of the program after processing (assuming that the function of the program is uppercase to lowercase) and then the hello to the function, and then this function is responsible for the ResponseTest Hello inserted into the innerHTML document

The function of implementing Ajax is to pass in the string hello-------to the handler that uses the open or the Send method to upload this hello to the background.

----the spooler to replace uppercase with lowercase hello------then this function is used document.getElementById ("show"). Innerhtml=x.responsetext; Insert well-handled Hello into HTML page

Go to the news and interview the first time I heard about Ajax, the essence is a function, and the function of background interaction

<script type= "Text/javascript" >functionCheck (str) {if(window. XMLHttpRequest) {varx=NewXMLHttpRequest ();//Create object x    }Else{        varx=NewActiveXObject ("Microsoft.XMLHTTP"); } x.open ("GET", "test2.php?c=" +str+ "&q=" +NewDate (),true);//open Methodclient ready to send to test2.php processingX.send ();//sent by the client. These 2 steps are requestsX.onreadystatechange=functionff () {if(x.readystate==4 && x.status==200) {//Client judgment Condition    //Client Displaydocument.getElementById ("Show"). innerhtml=X.responsetext; }  }                }     </script>

3. Background program

<? PHP if ($_get["C"]== "") {  // if $_get["C"] is empty echo "empty";    // The output is empty} Else {     // otherwise echo$_get["C"];     // output the data sent over }?>

Beginners must read native ajax-asynchronous JavaScript and XML

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.