【正文】
nteractions. void abort(): This method is really quite selfexplanatory— it stops the request. string getAllResponseHeaders(): The core functionality of this method should be familiar to Web application developers— it returns a string containing response headers from the HTTP request. Headers include ContentLength, Date, and URI. string getResponseHeader(string header): This method is a panion to getAllResponseHeaders() except it takes an argument representing the specific header value you want, returning this value as a string. In addition to these standard methods, the XMLHttpRequest object exposes the properties listed in Table 22. You’ll use these properties extensively when working with XMLHttpRequest. Table 22. Standard XMLHttpRequest Properties Property Description onreadystatechange The event handler that fires at every state change, typically a call to a JavaScript function. readyState The state of the request. The five possible values are 0 = uninitialized, 1 = loading, 2 = loaded, 3 = interactive, and 4 = plete. responseText The response from the server as a string. responseXML The response from the server as a string. The response from the server as XML. This object can be parsed and examined as a DOM object. status The HTTP status code from the server (that is, 200 for OK, 404 for Not Found, and so on). statusText The text version of the HTTP status code (that is, OK or Not Found, and so on). An Example Interaction At this point, you might be wondering what a typical Ajax interaction looks like. Figure 21 AjaxEnabled Web Application Web Container Client Server Database event Server source Figure 21. Standard Ajax interaction Unlike the standard request/response approach found in a standard Web client, an Ajax application does things a little bit differently. 1. A clientside event triggers an Ajax event. Any number of things can trigger this, from a simple onchange event to some specific user action. You might have code like this: input type=textd= name= onblur=validateEmail()。 the landscape is constantly changing, with new libraries and versions ing out regularly. As the field matures, the best ones will bee apparent. Some of the more mature libraries include libXmlRequest, RSLite, sarissa,JavaScript Object Notation (JSON), JSRS, Direct Web Remoting (DWR), and Ruby on Rails. This is a dynamic space, so keep your RSS aggregator tuned to those sites dedicated to posting about all things Ajax! Summary While Ajaxesque techniques have been used for many years, the recent adoption of the XMLHttpRequest object by modern browsers has ushered in a new era of developing rich Web applications. In this chapter, we established the basics of working with the heart of Ajax, the XMLHttpRequest object. At this point, you know the methods and properties of the XMLHttpRequest object, and we’ve shown you some simple examples of their use. As you can see, the object is pretty straightforward and hides much of its plexity from you. Combined with a healthy dose of JavaScript and some basic DOM manipulation, Ajax allows for a level of interactivity previously unmatched on the Web. 英文翻譯 使用 XMLHttpRequest 對(duì)象 我們已經(jīng)討論了動(dòng)態(tài) Web 應(yīng)用的發(fā)展歷史,并簡(jiǎn)要介紹了 Ajax,下面再來討論問題的關(guān)鍵:如何使用 XMLHttpRequest 對(duì)象。大多數(shù)使用統(tǒng)計(jì)表明,在當(dāng)前使用的瀏覽器中只有極少數(shù)不支持 XMLHttpRequest,所以一般情況下不會(huì)存在這個(gè)問題。你要做的只是檢查瀏覽器是否提供對(duì) ActiveX 對(duì)象的支持。不要擔(dān)心,稍后就會(huì)詳細(xì)介紹這些方法。它有兩個(gè)必要的參數(shù),還有 3 個(gè)可選參數(shù)。 void send(content):這個(gè)方法具體向服務(wù)器發(fā)出請(qǐng)求。XMLHttpRequest 對(duì)象還有許多屬性,