网页设计外文翻译---使用xmlhttprequest对象(编辑修改稿)内容摘要:

ly 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()。 2. An instance of the XMLHttpRequest object is created. Using the open() method, the call is set up— the URL is set along with the desired HTTP method, typically GETor POST. The request is actually triggered via a call to the send() method. 3. A request is made to the server. This might be a call to a servlet, a CGI script, or any serverside technique. 4. The server can do anything you can think of, including accessing a data store or even another system. 5. The request is returned to the browser. The ContentTypeis set to text/xml— the XMLHttpRequest object can process results only of the text/html type. In more plex instances, the response might be quite involved and include JavaScript, DOM manipulation, or other related technologies. Note that you also need to set the headers so that the browser will not cache the results locally. You do this with the following code: (CacheControl, nocache)。 (Pragma, nocache)。 In general, the various frameworks and toolkits available on the Web take care of the basic wiring and the browser abstractions, and some add user interface ponents. Some are purely client based。 others require work on the server. Many of these frameworks have just begun development or are in the early phases of release。 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 show。
阅读剩余 0%
本站所有文章资讯、展示的图片素材等内容均为注册用户上传(部分报媒/平媒内容转载自网络合作媒体),仅供学习参考。 用户通过本站上传、发布的任何内容的知识产权归属用户或原始著作权人所有。如有侵犯您的版权,请联系我们反馈本站将在三个工作日内改正。