Ajax implements the login function and ajax implements Login
The full name of AJAX is Asynchronous Javascript and XML (Asynchronous Javascript and XML ).
Advantages of ajax:
1. The biggest difference is that the page is refreshing and the user experience is very good.
2. Use asynchronous mode to communicate with the server, providing more rapid response capabilities ..
3. Some of the previous server workload can be transferred to the client, and the client's idle capabilities can be used to handle the workload, reduce the load on servers and bandwidth, and save space and bandwidth rental costs. In addition, it reduces the burden on the server. The ajax principle is to "retrieve data on demand", which can minimize the burden on the server caused by redundant requests and responses.
4. Based on standardized and widely supported technologies, you do not need to download plug-ins or applets.
5. ajax can make Internet applications smaller, faster, and more friendly.
Here I use ajax to write a simple login page: The first thing I need is the database login table,
The following is the logon Page code. First, introduce the jquery package.
<Head> <meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8 "/> <title> untitled document </title> <script src =" jquery-3.1.1.min.js "> </script>/* introduce jquery package */
The login page is very simple, so you won't be able to log on to it. I 've written this blog many times.
Then the following is how ajax is written:
<Script type = "text/javascript"> $ ("# btn "). click (function () {// Step 1: retrieve data. the user name and password var uid are used here = $ ("# uid "). val (); var pwd = $ ("# pwd "). val (); // Step 2: verify the data. Here we need to call the data from the database, and we use ajax $. ajax ({url: "dlchuli. php ", // request address data: {uid: uid, pwd: pwd}, // type of the submitted data:" POST ", // dataType: "TEXT", // return type TEXT string json xml success: function (data) {// before the start, use trim () if (data. trim () = "OK") {window. location. href = "main. php ";}else {alert (" incorrect user name or password ") ;}}})}) </script>
The code for dlchuli. php is as follows:
<?phpinclude("DADB.class.php");$db=new DADB();$uid=$_POST["uid"];$pwd=$_POST["pwd"];$sql="select password from login where username='{$uid}'";$arr=$db->Query($sql);if($arr[0][0]=$pwd && !empty($pwd)){ echo"OK";}else{ echo"NO";}?>
Here, you can use ajax to write a simple login page. The biggest benefit is that if an error occurs on the original page, it will not be reported to other pages.
The above is all the content of this article. I hope this article will help you in your study or work. I also hope to provide more support to the customer's home!