AJAX uses the XMLHttpRequest object

To get or send information from/to a database or a file on the server with traditional JavaScript, you will have to make an HTML form, and a user will have to click the "Submit" button to send/get the information, wait for the server to respond, then a new page will load with the results. Because the server returns a new page each time the user submits input, traditional web applications can run slowly and tend to be less user-friendly.

With AJAX, your JavaScript communicates directly with the server, through the JavaScript XMLHttpRequest object.

With the XMLHttpRequest object, a web page can make a request to, and get a response from a web server - without reloading the page. The user will stay on the same page, and he or she will not notice that scripts request pages, or send data to a server in the background.


The XMLHttpRequest object

By using the XMLHttpRequest object, a web developer can update a page with data from the server after the page has loaded!

AJAX was made popular in 2005 by Google (with Google Suggest).

Google Suggest is using the XMLHttpRequest object to create a very dynamic web interface: When you start typing in Google's search box, a JavaScript sends the letters off to a server and the server returns a list of suggestions.

The XMLHttpRequest object is supported in all major browsers (Internet Explorer, Firefox, Chrome, Opera, and Safari)




AJAX采用XMLHttpRequest对象
采用的传统的JavaScript对服务器上的数据库或文件进行读取的话,你不得不在网页中制作一个表单,然后用户点击表单中的“提交”按钮以便向服务器发送信息,并等待服务器的回应,然后一个包含有结果信息的新网页将在浏览器中载入。因为用户每次提交新的输入时服务器都会返回一个新网页,所以传统的Web应用程序都表现的比较慢而且缺乏界面缺乏友善性。

采用了AJAX后,JavaScript直接与服务器进行通讯。

通过XMLHttpRequest对象,网页可以像服务器发送请求并接收服务器的响应,而非传统的重新载入整个网页的方式。用户将停留在同一个网页,并且用户不会注意到脚本程序在后台与服务器请求、响应的工作。




通过XMLHttpRequest对象,一个Web程序员可以再网页载入后更新网页中的数据。
Google Suggest采用了XMLHttpRequest对象来建立动态网页接口:当你开始在Google的搜索框中输入时,一个Javascript将用户输入的字符发送到服务器上,服务器返回一个单词自动补全的列表。
几乎所有的浏览器都支持XMLHttpRequest对象(IE,FireFox,Chrome,Opera,Safari)。




本文英文网址:http://www.w3schools.com/Ajax/ajax_httprequest.asp

posted on 2009-07-24 17:04  Yean  阅读(329)  评论(0)    收藏  举报