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的局限性,<