异步Javascript和XML(Ajax)是一个描述在客户端脚本和服务器之间传输数据过程的名词。它的优点是给开发者提供了一种从Web服务器接受内容而不用重新刷新用户当前正在浏览的页面的方式。
Asynchronous JavaScript and XML (Ajax) is a term for the process of
transferring data between a client script and the server. The advantage of
this is that it provides developers with a way to retrieve content from a
Web server without reposting the page the user is currently viewing to the
server. In concert with modern browsers’ ability to dynamically change
displayed content through programming code (JavaScript) that accesses
the browser's DOM, Ajax lets developers update the HTML content
displayed in the browser without refreshing the page. Thus, Ajax
provides dynamic interaction between a client and a server. In other
words, Ajax can make browser-based applications more interactive, more
responsive, and more like traditional desktop applications. Google's Gmail
and Outlook Express are two familiar examples that use Ajax techniques.
Ajax has various applications, some of which are discussed below.
1. Dynamic Form Data Validation. As an example, suppose a user fills
out a form to register with a web site.The validity of data in the form
is not checked till the form is submitted. With Ajax, the data added to
the form is dynamically validated using business logic in a server
application. Thus, a complete form does not have to be posted to the
server to check if data in the form is valid.
2. Auto completion. As a user adds some data to a form, the remaining
form gets auto completed.
3. Refreshing data on a page. Some web pages require that data be
refreshed frequently, a weather web site for example. Using the Ajax
technique, a web page may poll the server for latest data and refresh
the web page without reloading the page.
Ajax is based on XMLHttpRequest, JavaScript and XML DOM
technologies. JavaScript and XML DOM technologies are relatively old
technologies. Therefore we won’t discuss these. XMLHttpRequest is a relatively new technology. In the next section, we shall discuss the XMLHttpRequest technology.