A simple logon page for ajax writing

Source: Internet
Author: User

A simple logon page for ajax writing

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 and provide 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 use of 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.

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 logon page. The biggest benefit is that an error will be reported on the original page and will not jump to other pages.

The above is all the content of this article. I hope it will be helpful for your learning and support for helping customers.

Related Article

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.