-ajax
A. Full name: Asynchronous JavaScript and XML (asynchronous JavaScript and XML)
B. Meaning: A Web development technology for creating interactive Web applications
C. function: To achieve local refresh, reduce server pressure
D. Principle of work:
Traditional Web applications allow users to fill out forms and send an HTTP request to the Web server when submitting a form. The server receives and processes the form that came in,
Then return a new page to the user's browser. As the illustration shows, the traditional Web application works. When using traditional Web applications, to change the page
A small amount of data that needs to reload the entire page, which is an unfriendly user experience. And because each application's interaction needs to be sent to the server
Requests, the response time of the application depends on the response time of the server, which can cause the user to spend longer wait times.
Unlike traditional Web applications, Ajax uses an asynchronous interaction process. Ajax can only send and retrieve the necessary data to the server, which uses SOAP
(Simple Object Access Protocol) or some other xml-based Web Service interface, and use JavaScript on the client to handle the response from the server.
The data that the user obtains on the page is provided through the Ajax engine, because the page does not need to interact directly with the server, so the client browser does not need to brush
The new page will be able to get information about the server and improve the friendliness of the page.
Main:
code is as follows |
copy code |
function CallServer (value) { createxmlhttpobject (); //Create a XMLHTTP object xmlhttp.open ("Get", "for.php?id=" +value,true); Create an HTTP request xmlhttp.onreadystatechange=updatepage; //defines the function of the response xmlhttp.send (null); //Send request } |
Note:
1. Get the contents of a text box
A.document.myform.user.value (JS file)
B.this.value (in HTML file)
2. Note Character Set
if you output the results including Chinese, Be aware of the problem with the character set. That is, the character set of the JS file and the character set of the PHP file should be convertible
Example: I am using Easyeclipse, The new Ajax.js file's character set defaults to Iso-8859-1, so that the PHP file
should be UTF and not GBK, may be gkb and ISO can not convert the reason. and UTF more ' take all '. Of course, you can convert the
JS file to UTF8, which avoids a lot of problems.