Ajax basics and logon tutorials
Ajax is short for Asynchronous Javascript and XML.
Advantages of Ajax:
Advantage: reduces the burden on the server, obtains data on demand, and minimizes redundant requests.
Partial page refresh to reduce user psychology and actual waiting time, and bring a better user experience
Xml-based standardization, widely supported, and plug-ins not required
Further promote the separation of pages and Data
Ajax includes the following technologies:
Representation based on the web Standard (standards-based presentation) XHTML + CSS;
Use DOM (Document Object Model) for Dynamic Display and interaction;
Use XML and XSLT for data exchange and related operations;
Use XMLHttpRequest for asynchronous data query and retrieval;
Use Javascript to bind everything together.
That is to say, the biggest feature of Ajax is that it can achieve dynamic non-Refresh.
Use Ajax:
Example:
A table in the database:
Click to check whether the user name is available:
Homepage code:
<! DOCTYPE html>
The processing page is as follows:
<? Php $ zhang = $ _ POST ["yhm"]; // value include ("db. class. php "); $ db = new db (); $ SQL =" select count (*) from mydb where zhang = '{$ zhang }'"; $ arr = $ db-> Query ($ SQL); echo $ arr [0] [0]; // The direct output is equivalent to the return result?>
Figure:
Enter an existing User Name:
Enter a user name that does not exist:
Then write a login:
Logon Page code:
<! DOCTYPE html>
Next is the login processing page:
<? Phpinclude ("db. class. php "); $ db = new db (); $ zhang = $ _ POST [" zhang "]; $ mi = $ _ POST [" mi "]; // value: $ SQL = "select mi from mydb WHERE zhang = '{$ zhang}'"; $ arr = $ db-> Query ($ SQL ); if ($ arr [0] [0] ==$ mi &&! Empty ($ mi) {echo "OK" ;}else {echo "no" ;}?>
If the input is incorrect, the following message is displayed on this page:
Jump to the right of the input:
The advantage of using Ajax to write logs is that when an error is prompted, you do not need to jump to another page.
The above section describes the Ajax basics and logon tutorials. I hope this will help you. If you have any questions, please leave a message and I will reply to you in a timely manner. Thank you very much for your support for the help House website!