How JSON data is defined
1 //Write Data2 varA = {3Code: "P001",4Name: "Zhang San",5Shuzu:NewArray (1,2,3,4),6JSON:{AA: "AA", BB: "BB"},7Age:188 };9 //reading DataTenalert (A.code);
Ajax Way
$.ajax ({URL:"Chuli.php",//address passed inData:{u:uid},//passed ParametersType: "POST",//Way of passingDataType: "TEXT",//type of ReturnSuccessfunction(data) {//returns the function executed after success if(data== "OK") { varstr = "This user name can be used!" " $("#xinxi"). html (str); } Else { varstr = "<span style= ' color:red ' > The user name already exists </span>"; $("#xinxi"). html (str); } } });
Example: Using AJAX to implement no flush login
User name:<inputtype= "text"ID= "UID" />Password:<inputtype= "text"ID= "pwd" /><inputtype= "button"ID= "BTN"value= "Login" />
jquery Code
$ (document). Ready (function(e) {//Add a Click event to the login button$ ("#btn"). Click (function(){ //remove a value from two text boxes varUID = $ ("#uid"). Val (); varPWD = $ ("#pwd"). Val (); Call Ajax $.ajax ({URL:"Dlchuli.php", Data:{u:uid,p:pwd}, type:"POST", Dayetype:"TEXT", Success:function(date) {//If you return to the OK jump page if(date== "OK") {window.location= "text1.php"; } //failure to sign in if you regret no prompt Else{alert ("Login failed!" "); } } }); }) });
Login Processing Page
1 //receive the passed value2 $uid=$_post["U"];3 $pwd=$_post["P"];4 //introduce classes that access the database5 include(".. /dbda.class.php ");6 $db=NewDbda ();7 $sql= "SELECT * from Users where uid= ' {$uid} ' and pwd= ' {$pwd}‘";8 $attr=$db->query ($sql);9 //if the query results to 1 indicate that the user name and password are correct, return OKTen if($attr[0] [0]==1) One { A Echo"OK"; - } - //otherwise incorrect description, return no the Else - { - Echo"NO"; -}
PHP JSON data AJAX