Using a simple example, the input of the form, the form input in the form of JSON, and back in the background JSON format, using the JS function processing, display, further familiar with the use of Ajax, as well as JSON usage. Examples are as follows:
HTML section: <form action= "test1.php" method= "Get" onsubmit= "Return check ();" > <label for= "username" > User name </label><input type= "text" Placeholder= "Please enter user name" id= "username" ><br><label for= "usernum" > study number </label><input type= "text" placeholder= "Please enter the study number" id= "Usernum" onblur= "Checkform ();" ><br> <input type= "Submit" value= "Submission" > < Div id= "Tips" ></div> </form> js part: <script>var xmlobj;var Result=false;function createxmlhttprequest () {if (window. ActiveXObject) { xmlobj=new activexobject ("Microsoft.XMLHTTP");} Else if (window. XMLHttpRequest) {xmlobj=new xmlhttprequest ();}} Function check () {if (Resultform ()) {return true;} Else{return faLSE;}} function checkform () { var usernameobj=document.getelementbyid (' username '). value;var usernumobj= document.getElementById (' Usernum ') .value;var data={username:usernameobj,usernum:usernumobj};var Jsonobj=json.stringify (data);//Convert object to JSON string, pass through Ajax var cb = ajaxresultdeal; url= ' test.php?data= ' +jsonobj+ "&r=" + Math.random (); toajax (URL,CB); } function toajax (Url,callback) { createxmlhttprequest (); Xmlobj.onreadystatechange=function () {if (xmlobj.readystate==4&&xmlobj.status==200) { callback ( Xmlobj.responsetext); &nBsp; }else{result=false;}} xmlobj.open ("GET", url,true);/*xmlobj.setrequestheader ("Content-type", "application/x-www-form-urlencoded" ); xmlobj.send (data); */xmlobj.send (null);} Function ajaxresultdeal (response) { var tips=document.getelementbyid (' tips '); var json=json.parse (response) ; if (json[' username ']== "one") { tips.innerhtml= ":
When the user name is 11 o'clock, enter the correct
650) this.width=650; "src=" http://s5.51cto.com/wyfs02/M01/7F/A3/wKioL1cnINLS--nHAAAuceDgEdc809.jpg "title=" 1.jpg " alt= "Wkiol1cninls--nhaaaucedgedc809.jpg"/>
When the user name is not 11 o'clock, the output is:
650) this.width=650; "src=" http://s1.51cto.com/wyfs02/M02/7F/A5/wKiom1cnICWw2krtAAAtokV0QVI383.jpg "title=" 2.jpg " alt= "Wkiom1cnicww2krtaaatokv0qvi383.jpg"/>
This article is from the "dream need to adhere to" blog, please be sure to keep this source http://xiyin001.blog.51cto.com/9831864/1769505
Ajax Small Demo-----The use of JSON in Ajax