Ajax利用了一个已被内置在所有主流浏览器里的对象——XMLHttpRequest,来发送和接收HTTP请求响应。
Ajax takes advantage of an object built into all modern browsers-the
XMLHttpRequest object-to send and receive HTTP requests and
responses. An HTTP request sent via the XMLHttpRequest object does
not require the page to have or post a <form> element. The “A” in Ajax
stands for “asynchronous”, which means that the XMLHttpRequest
object's send() method returns immediately, letting the browser
processing of other HTML/JavaScript on the Web page continue while the
server processes the HTTP request and sends the response. While
asynchronous requests are the default, the reader can optionally send
synchronous requests, which halt other Web page processing until the page
receives the server's response.
Microsoft introduced the XMLHttpRequest object as an ActiveX
object in Internet Explorer (IE) 5. Other browser manufacturers,
recognizing the object's utility, implemented the XMLHttpRequest
object in their browsers, but as a native JavaScript object rather than as an
ActiveX object. In turn, recognizing the value and security in that
implementation type, Microsoft has recast the XMLHttpRequest in IE
7 as a window object property. Even when the implementation (and thus
invocation) details differ, all the browsers' implementations have similar
functionality and essentially identical methods. The W3C is working to
standardize the XMLHttpRequest object, releasing a working draft of
the W3C specification1.
This chapter discusses the XMLHttpRequest object API in detail,
listing and explaining all the properties and methods.