The full name of Ajax is asynchronous JavaScript and XML (asynchronous JavaScript and XML).
Advantages of Ajax:
1, the biggest point is that the page does not refresh, the user experience is very good.
2, the use of asynchronous way to communicate with the server, with more rapid response capability.
3, can transfer the work of some previous server to the client, take advantage of the client idle ability to handle, reduce the burden of server and bandwidth, save space and broadband rental cost. and reduce the burden on the server, the principle of Ajax is "on-demand data", can minimize redundancy requests, and response to the burden on the server.
4, based on standardized and widely supported technology, do not need to download plug-ins or small programs.
5. Ajax can make Internet applications smaller, faster, and more friendly.
Here I use Ajax to write a simple login page: The first is to use the database login table,
Here is the code for the login page, first to introduce the jquery package
1 <Head>2 <Metahttp-equiv= "Content-type"content= "text/html; charset=utf-8" />3 <title>Untitled Document</title>4 <Scriptsrc= "Jquery-3.1.1.min.js"></Script>/ * Introduction of jquery Package * /5 </Head>6 <Body>7 <H2>Login Page</H2>8 <Div>User name:<inputtype= "text"ID= "UID"/></Div>9 <Div>Password:<inputtype= "text"ID= "pwd"/></Div>Ten <Div><inputtype= "button"ID= "BTN"Value= "Login"/></Div> One</Body> A</HTML>
Login page is very simple, no, the previous blog has been written many times
And here's the Ajax notation.
1<script type= "Text/javascript" >2$ ("#btn"). Click (function(){3 //The first step: Take the data, here use the user name and password4 varuid=$ ("#uid"). Val ();5 varpwd=$ ("#pwd"). Val ();6 //The second step: Validating the data, here we need to tune the data from the database, we use the Ajax7 $.ajax ({8URL: "dlchuli.php",//Request Address9DATA:{UID:UID,PWD:PWD},//submitted DataTenType: "POST",//How to submit OneDataType: "TEXT",//return type text string JSON XML ASuccessfunction(data) { - //before you start, go to the blanks with trim () - if(Data.trim () = = "OK") the { -Window.location.href = "main.php"; - } - Else{ +Alert ("User name or password error"); - } + } A }) at - }) -</script>
dlchuli.php code is written as follows:
1<?PHP2 include("DADB.class.php");3 $db=Newdadb ();4 $uid=$_post["UID"];5 $pwd=$_post["PWD"];6 $sql= "Select password from login where username= ' {$uid}‘";7 8 $arr=$db->query ($sql);9 Ten if($arr[0] [0]=$pwd&&!Empty($pwd)) One { A Echo"OK"; - } - Else{ the Echo"NO"; - } -?>
Write here, with Ajax write simple login page completed, the biggest advantage is that if the error will be in the original page error, will not jump to other pages
Ajax Write Login