Ajax. Full case

Source: Internet
Author: User

PHP notation<?php$id = $_get[' id ']; if($id= =1) { $arr[' name '] = "three squirrels"; $arr[' money '] = +; $arr[' Guige '] = "3 bags"; $arr["Love"] = 1; $arr["SRCC"]= "img7_03.png"; echo Json_encode($arr); }Else { $arr = "Please enter ID"; }?><! DOCTYPEhtml> <html> <head> <meta charset="UTF-8"> <title></title> </head> <body> <div class= "" id="box"> <img src= "" " alt= " "/><p class="P1"> Name </p><p class="P2"> Money </P><p class="P3"> Specifications </P> <p class="P4"> Love </P> <button> Click </button> <a href=""></a> /c13></div>       </Body> <script type="Text/javascript"> var p1=document. Queryselector (". P1"); var p2=document. Queryselector (". P2"); var p3=document. Queryselector (". P3"); var p4=document. Queryselector (". P4"); var btn=document. Queryselector ("button"); var imgs=document. Queryselector ("img"); var ap=document. Queryselector ("a");              //Do compatible processing. Create a new object http://www.jb51.net/article/23175.htm if(window. XMLHttpRequest) { //Create a new object var ajax = new XMLHttpRequest (); }Else{ var ajax = new ActiveXObject ();             }            btn. onclick=function() { //open, in what way, the file has ID write ID, synchronous or asynchronous Ajax.open ("GET","new_file.php?id=1",true); Ajax.send (); / * Send data * /                     /*ajax, when a request is sent to the server when the event changes, we need to perform some response-based tasks. */, http://www.w3school.com.cn/ajax/ajax_xmlhttprequest_onreadystatechange.asp Ajax. onReadyStateChange = function() { / * Determine if success is successful */http://blog.csdn.net/u013381651/article/details/51261956 if(ajax.readystate= =4) { The onreadystatechange event is triggered whenever the readyState changes. if(ajax.status==) { //gets its object converted to an integer * / var obj=json.parse (ajax.responsetext); p1.innerhtml="name"+obj.name; p2.innerhtml="Money"+Obj.money; p3.innerhtml="Specification"+obj.guige; p4.innerhtml="Love"+obj.love; / * To get the Print object in the form of a point * / imgs.src=obj.srcc; /*a.href=obj.html;*/                               / * To get the Print object in the form of a point * /                        }                  }            }                                                }             </script> </html>

Ajax. Full case

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.