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