如果您完全不熟悉 AJAX(代表异步 Javascript 和 XML),维基百科上的 AJAX 条目是一个很好的起点,还有更多链接,例如 Link1 或 Link2:
Like DHTML and LAMP, AJAX is not a technology in itself, but a group of technologies. AJAX uses a combination of:
HTML and CSS for marking up and styling information.
The DOM accessed with JavaScript to dynamically display and interact with the information presented.
A method for exchanging data asynchronously between browser and server, thereby avoiding page reloads. The XMLHttpRequest (XHR) object is usually used, but sometimes an IFrame object or a dynamically added tag is used instead.
A format for the data sent to the browser. Common formats include XML, pre-formatted HTML, plain text, and JavaScript Object Notation (JSON). This data could be created dynamically by some form of server-side scripting.
如您所见,从纯技术的角度来看,这里并没有什么新东西。大多数 AJAX 部分在 1994 年就已经存在(1999 年用于 XMLHttpRequest 对象)。真正的新颖之处在于将这些部分一起使用,就像 Google 对 GMail (2004) 和 Google Maps (2005) 所做的那样。实际上,这两个网站都对 AJAX 的推广做出了重大贡献。
一张价值千言万语的图片,下面的图表说明了客户端和远程服务器之间的通信,以及经典应用程序和基于 AJAX 的应用程序之间的区别:
对于橙色部分,您可以手动完成所有操作(使用 XMLHttpRequest 对象),或者您可以使用著名的 JavaScript 库(如 jQuery、Prototype、YUI 等)来“AJAXify”应用程序的客户端。此类库旨在隐藏 JavaScript 开发的复杂性(例如跨浏览器兼容性),但对于一个简单的功能来说可能是多余的。
在服务器端,一些框架也可以提供帮助(例如,如果您使用 Java,则可以使用 DWR 或 RAJAX),但您需要做的基本上就是公开一个服务,该服务仅返回部分更新页面所需的信息(最初是 XML/XHTML——AJAX 中的 X——但现在通常首选 JSON)。