摘要:AJAXDEFINITION:AsynchronousJavaScriptandXML(AJAX)isanapproachtodevelopingWebapplicationsinwhichclientWebpagesaremodifiedasynchronouslyandincrementallyratherthanbeingreplacedentirelyeverytimeanupdateisneeded.AlthoughtheacronymAJAXisfairlystraightforward,it’
AJAX
DEFINITION: Asynchronous JavaScript and XML (AJAX) is an approach to developing Web applications in which client Web pages are modified asynchronously and incrementally rather than being replaced entirely every time an update is needed.
Although the acronym AJAX is fairly straightforward, it’s significant because it captures a paradigm shift in the delivery of Web page content.
The AJAX approach to Web content delivery speeds up the user interface. The long wait for an entire page to refresh from a Web server isn't necessary in an AJAX-based application. Only that part of a Web page that needs to be updated is altered, and the update is done locally, if possible, and asynchronously. The user can continue to interact with the Web page while JavaScript on the client minimizes interactions with the server, and information passing between client and server is done in the background.
For developers not yet using AJAX, any change to a Web page requires a full client/server interaction. For example, a request to insert a newly typed item into a list requires a series of steps: After the new item name is entered into a form, it’s passed back to a server. The server then generates a new Web page. That page is transmitted back to the client, and the client’s entire Web page screen gets refreshed. The URL at the top of the Web page reflects the transaction that has just occurred.
In contrast, in an AJAX-based Web application, the interaction looks like this: The user types a new item into an input box. JavaScript, running on the user’s computer, inserts the item into the list and refreshes only a few lines of the Web page. The server is entirely cut out of the interaction, and the URL at the top of the Web page doesn’t change.
Even if client/server interaction had been needed, the response time of the user interface would have been more like that of a program running solely on the local machine.
The AJAX acronym was born on Feb. 18, 2005, when it first appeared in a paper titled “Ajax: A New Approach to Web Applications”, which was written by Jesse James Garrett, a founder of Web consultancy Adaptive Path LLC. The term has generated a lot of buzz among developers and bloggers so far this year, but it’s only the name that’s new.
In his essay, Garrett points to existing Google applications—Google Groups, Suggest, Maps and Gmail—as examples of the new paradigm in Web interaction design. Google Maps doesn’t jerk and stall as a user pans the field of view across an apparently limitless map. The older paradigm requires the user to click on an arrow in the requested panning direction, which is followed by an hourglass hiatus while the map server creates the desired view and downloads it to the local machine.
The following technologies and protocols used in AJAX had been around for a while before Garrett specified them in his essay:
● XHTML and Cascading Style Sheets (CSS) for presentation.
● Document Object Model for dynamic display.
● XML and Extensible Stylesheet Language Transformations for data interchange.
● Microsoft’s XMLHttpRequest for asynchronous client/server interaction.
● JavaScript to run commands on the client machine.
Until recently, however, some crucial pieces weren’t in place to bring the technologies together. Without the wide adoption of broadband, downloading the required JavaScript for local control (often as much as 10,000 to 20,000 lines of code) took too long.
Not all applications may be right for the AJAX approach. Skeptics frequently cite “breaking the Back button” as a serious problem. Because AJAX allows Web pages to be modified locally and/or incrementally, clicking on the Back button doesn’t necessarily return a user to the previous page. The Back button may take the user all the way back to the beginning of a long interaction—the one specified by the URL shown at the top of the Web page.
For the same reason, the URL at the top of the Web page doesn’t com-pletely specify the contents of a page, so it may be impossible to bookmark desired pages or share URLs so that others may see the same Web content. And asynchronous updates mean that a Web page could adjust its shape, layout or length unexpectedly.
Despite those drawbacks, AJAX has generated real excitement with its promise of more-responsive Web interactions. Garrett ends his essay with this Utopian vision: “The biggest challenges in creating Ajax applications are not technical. ... The challenges are for the designers of these applications: to forget what we think we know about the limitations of the Web, and begin to imagine a wider, richer range of possibilities.”
AJAX
定義:異步JavaScript和XML(AJAX)是一種開發Web應用程序的方法,其中當需要更新時,客戶端Web頁面的修改是異步的和逐步進行的,而不是被徹底替代。
雖然AJAX這個縮寫字相當簡單直白,但它很有意義,因為它在提交Web頁面內容時選擇了一種新的方式。
提交Web頁面內容的AJAX方法提高了用戶界面的速度。在基于AJAX的應用程序中沒有必要長時間等待整個頁面的刷新。頁面中只有需要更新的那部分才更改,如果可能的話,更新是本地完成的,并且是異步的。客戶端的JavaScript將與服務器的交互減至最少的同時,用戶能連續與Web頁面交互,而且客戶端和服務器之間的信息傳遞是在后臺進行的。
對于那些尚未使用AJAX的開發者而言,Web頁面的任何修改都需要完整的客戶端/服務器交互。例如,對于將新鍵入的新項目插入一張列表這樣的請求,需要完成一系列的步驟:在新項目的名字輸入到表格之后,它被送回到服務器,然后服務器生成新的Web頁面。該頁面被發回到客戶端,客戶端的整個Web頁面屏幕得到刷新。Web頁面上部的網址反映出剛剛發生的交互。
相反,在基于AJAX的Web應用程序中,交互看上去是這樣的: 用戶在輸入框內敲入新的項。運行在用戶計算機中的JavaScript將該項插入列表,并只刷新該頁面中的幾行。服務器完全被排除在交互之外,Web頁面上部的網址也沒有變化。
即使真的需要客戶端/服務器交互,從用戶界面的響應時間上看,也更像是在本地機器上運行的程序的響應時間。
AJAX這個縮寫誕生于2005年2月18日,這天它第一次出現在Jesse James Garrett撰寫的一篇題為“Ajax: A New Approach to Web Applications”(Ajax:編寫Web應用程序的新方法)的論文中,Jesse James是一家Web咨詢公司——Adaptive Path LLC的創始人。今年以來,在開發人員和博客中間此術語成了熱門話題,不過僅僅這個名字是新的。
Garrett在他的論文中指出,現有的Google應用程序(Google Groups, Suggest, Maps,Gmail)是Web交互設計中新方法的例子。當用戶在看來是無限制的地圖上變換焦點時,Google Maps不會急劇動作或停止不動。而老的方法需要用戶在想要轉動的方向上點擊箭頭,接下來出現沙漏,同時地圖服務器生成所需的視圖,以及將其下載到本地的機器上。
下列用于AJAX的技術和協議Garrent在其論文中對它們做出規定之前已經存在多時:
● XHTML和級聯式樣板(CSS),用于演示。
● 文檔對象模型,用于動態顯示。
● XML和擴展的樣板語言轉換,用于數據交換。
● 微軟的XMLHttpRequest,用于異步的客戶端/服務器交互。
● JavaScript使命令在客戶機上運行。
然而,時至今日,有些關鍵的東西還沒有到位,影響了技術的整合。如寬帶沒有廣泛采用,下載用于本地控制的JavaScript(常常高達1萬至2萬行代碼)需要太長的時間。
不是所有的應用程序都適用AJAX方法。懷疑論者常常把“破壞后退鍵”說成是一個嚴重的問題。由于AJAX允許Web頁面本地和(或)部分修改,所以點擊后退鍵并不是一定能讓用戶后退到先前的頁面。后退鍵可能讓用戶直接回到已經進行了多次交互的起始點—由Web頁面上方顯示的網址指定的那個起始點。
鑒于同樣的理由,Web頁面上方的網址沒有完整地指定頁面內容,所以不大可能給所要的頁面做書簽或者共享網址,以使其他的人可以看到同樣的Web內容。異步更新意味著Web頁面可以意想不到地調整其形狀、排列或長度。
盡管有這些不足之處,但AJAX以其更好的響應Web交互的承諾,讓我們真的動心。Garrett以烏托邦式的預見在論文的結束語中說:“編制Ajax應用程序的最大挑戰不是技術的,對這些應用程序的設計師而言,挑戰是:忘記那些我們以為知道的Web的局限性,<
軟考備考資料免費領取
去領取