PHP JSON data AJAX

Source: Internet
Author: User
Tags php json

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

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.