Ajax Implementation Login Interface

Source: Internet
Author: User

Using the PHP jump interface and Ajax can be used to implement the login interface to jump the login failure of the reminder. However, the way PHP jumps

Additional interfaces need to be loaded and the user experience is poor. Ajax enables the current page to refresh only the required data, not the current page

Reload or jump.

To do a simple login interface:

<div id= "" > User name: <input type= "text" name= "" id= "UID" value= ""/></div><div id= "" > Password: <input ty Pe= "text" name= "" id= "pwd" value= ""/></div><div id= "" ><input type= "button" name= "" id= "Denglu" value = "Login"/></div>

  

Then the JS code, the use of JQ is relatively simple, so first introduce the JQ file package.

Next get the user name and password value:

var uid = $ ("#uid"). Val (); var pwd = $ ("#pwd"). Val ();

  

After setting up, you can set up Ajax:

$.ajax ({type: "post", url: "dengluchuli.php", data: {u:uid,p:pwd},datatype: "TEXT", Success:function (r) {                    /// R is the return value if (r.trim () = = "Y") {              //y is the value returned in the URL Jump Web page. Window.location.href = "Jump Interface";} else {alert ("User name or password error");}});

  

dengluchuli.php:
<?phpinclude ("AJAXLOGIN.class.php"), $dd = new LoGin ($_post["U"],$_post["P"]); $ae = $dd:: Logi ("Login", "username", "password", "name"); is the table name in the database  , the user name in the table, the password, the name (the data is imported from the database)?>

  

Here I introduced a login class (AJAXLOGIN.class.php), which is intended for later convenience:

<?phpclass dbda{public $host = "localhost";p ublic $uid = "root";p ublic $pwd = "";p ublic $dbname = "12345";//Member Method public fu Nction Query ($sql, $type =1) {$db = new mysqli ($this->host, $this->uid, $this->pwd, $this->dbname); $r = $db- >query ($sql), if ($type ==1) {return $r->fetch_all ();} Else{return $r;}}} Class login{public static $uid;p ublic static $pwd; function __construct ($x, $y)    {self       :: $uid = $x;   Self:: $pwd = $y;    }  static function Logi ($table, $username, $password, $name) {$db = new Dbda (); $nnn = self:: $uid; $sql = "Select $name, $password From $table where $username = ' $nnn ', $at = $db->query ($sql), $p = self:: $pwd, if (!empty ($p) && $p = = $at [0][1]) {$ _session["UID"]= $at [0][0];echo "Y";} Else{echo "n";}}? >

  

  

Login Interface Complete code:

<!doctype html>

  

Ajax Implementation Login Interface

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.