Ajax (programming)
From Wikipedia, the free encyclopedia
Asynchronous JavaScript And XML, or its acronym Ajax, is a Web development technique for creating interactive web applications. The intent is to make web pages feel more responsive by exchanging small amounts of data with the server behind the scenes, so that the entire Web page does not have to be reloaded each time the user makes a change. This is meant to increase the Web page's interactivity, speed, and usability.
The Ajax technique uses a combination of:
- XHTML (or HTML), CSS, for marking up and styling information.
- The DOM accessed with a client-side scripting language, especially ECMAScript implementations like JavaScript and JScript, to dynamically display and interact with the information presented.
- The XMLHttpRequest object to exchange data asynchronously with the web server. In some Ajax frameworks and in some situations, an IFrame object is used instead of the XMLHttpRequest object to exchange data with the web server.
- XML is commonly used as the format for transferring data back from the server, although any format will work, including preformatted HTML, plain text, JSON and even EBML.
Like DHTML, LAMP, or SPA, Ajax is not a technology in itself, but a term that refers to the use of a group of technologies together. In fact, derivative/composite technologies based substantially upon Ajax, such as AFLAX, are already appearing.
Contents[hide] |
History
Most histories of Ajax start with Microsoft's initiatives in developing Remote Scripting.
However techniques for the asynchronous loading of content on an
existing web page without requiring a full reload date back as far as
the IFRAME element type (introduced in Internet Explorer 3 in 1996) and
the LAYER element type (introduced in Netscape 4 in 1997, abandoned
during early development of Mozilla). Both element types had a src
attribute that could take any external URL, and by loading a page containing javascript that manipulated the parent page, AJAX-like effects could be attained.
Microsoft's Remote Scripting (or MSRS, introduced in 1998) acted as a more elegent replacement for these techniques, with data being pulled in by Java applet which the client side could communicate with using JavaScript. This technique worked on both Internet Explorer version 4 and Netscape Navigator version 4 onwards.
The web development community, first collaborating via the microsoft.public.scripting.remote newsgroup and later through blog aggregation, subsequently developed a range of techniques for remote scripting in order to enable consistent results across different browsers. Early examples include JSRS library from 2000, the introduction of the Image/Cookie technique in 2000, and the JavaScript on Demand technique in 2002. In 2002, a user-community modification to Microsoft Remote Scripting was made to replace the Java applet with XMLHttpRequest.
Remote Scripting Frameworks such as ARSCIF surfaced in 2003 not long before Microsoft introduced Callbacks in ASP.NET
Since XMLHttpRequest is now implemented across the majority of browsers in use, alternative techniques are used infrequently. However, they are still used where wide compatibility, small implementation, or cross-site access are required. One alternative, the SVGT protocol, employs a persistent connection for continuous exchange between browser and service.
Articles
Some early articles promoting Remote Scripting techniques:
- Microsoft Internet Developer Magazine 1998
- ScottAndrew's XML-RPC example 2001
- Apple Developer Connection 2002
- Using the XML HTTP Request object 2002-2006
Pros, cons and criticism
Pros
Interactivity
Ajax applications are mainly executed on the user's machine, by manipulating the current page within their browser using document object model methods. Ajax can be used for a multitude of tasks such as updating or deleting records;expanding web forms; returning simple search queries; or editing category trees -- all without the requirement to fetch a full page of HTML each time a change is made. Generally only small requests are required to be sent to the server, and relatively short responses are sent back. This permits the development of more interactive applications featuring more responsive user interfaces due to the use of DHTML techniques.
Portability
Ajax applications use well-documented features present in all major browsers on most existing platforms. Though this situation could feasibly change in the future, at the moment, Ajax applications are effectively cross-platform.
While the Ajax platform is more restricted than the Java platform, current Ajax applications effectively fill part of the one-time niche of Java applets: extending the browser with lightweight mini-applications.
Cons and criticism
Usability criticisms
One major complaint voiced against the use of Ajax in web applications is that it might easily break the expected behavior of the browser's back button (see Jakob Nielsen's 1999 Top-10 New Mistakes of Web Design). The different expectations between returning to a page which has been modified dynamically versus the return to a previous static page might be a subtle one. Users generally expect that clicking the back button in web applications will undo their last state change and in Ajax applications this might not be the case. Developers have implemented various solutions to this problem, most of which revolve around creating or using invisible IFRAMEs to invoke changes that populate the history used by a browser's back button. Google Maps, for example, performs searches in an invisible IFRAME and then pulls results back into an element on the visible web page; it is possible to track user behaviour via callbacks which are called whenever the back button is pressed, restoring the application state that existed at the time.
A related issue is that dynamic web page updates make it difficult for a user to bookmark a particular state of the application. Solutions to this problem exist, many of which use the URL fragment identifier (the portion of a URL after the '#' [1]§4.1 and [2]§3.5) to keep track of, and allow users to return to, the application in a given state. This is possible because many browsers allow JavaScript to update the fragment identifier of the URL dynamically, so that Ajax applications can maintain it as the user changes the application's state[3]. This solution also improves back-button support.
Response-time concerns
Network latency — or the interval between user request and server response — needs to be considered carefully during Ajax development. Without clear feedback to the user [4], smart preloading of data [5], and proper handling of the XMLHttpRequest object [6] users might experience delay in the interface of the web application, something which users might not expect or understand. [7] The use of visual feedback to alert the user of background activity and/or preloading of content and data are often suggested solutions to these latency issues.
In general the potential impact of latency has not been "solved" by any of the Public Domain AJAX toolkits and frameworks available today, such as the effect of latency variance over time [8].
JavaScript
While no browser plug-in is required for Ajax, it requires users to have JavaScript enabled in their browsers. This applies to all browsers that support Ajax except for Microsoft Internet Explorer 6 and below which additionally require ActiveX to be enabled, as the XMLHttpRequest object is implemented with ActiveX in this browser. Internet Explorer 7, however, will implement this interface as a native JavaScript object and hence does not need ActiveX to be enabled for Ajax to work.
As with DHTML applications, Ajax applications must be tested rigorously to deal with the quirks of different browsers and platforms. A number of programming libraries have become available as Ajax has matured that can help ease this task. Likewise, techniques have been developed to assist in designing applications which degrade gracefully and offer alternative functionality for users without JavaScript enabled.
Name issues
There have been some critics of the term Ajax, claiming that Adaptive Path (the consulting firm that coined the term [9]) or other proponents are using it as a marketing vehicle for previously-used techniques [10] [11] [12] [13].
Accessibility
Using Ajax technologies in web applications provides many challenges for developers interested in adhering to WAI accessibility guidelines. Developers need to provide fallback options for users on other platforms or browsers, as most methods of Ajax implementation rely on features only present in desktop graphical browsers.
Web developers use Ajax in some instances to provide content only to specific portions of a web page, allowing data manipulation without incurring the cost of re-rendering the entire page in the web browser. Non-Ajax users would optimally continue to load and manipulate the whole page as a fallback, allowing the developers to preserve the experience of users in non-Ajax environments (including all relevant accessibility concerns) while giving those with capable browsers a much more responsive experience.
Markup language vs programming
The common approach to apply Ajax usually involves extensive programming in JavaScript. Frameworks are then aimed to provide ready-to-use UI (e.g., in HTML or XUL) widgets and libraries to make programming in JavaScript easier.
The major advantage of the declarative approach is that non-programmers are allowed to define user interfaces with HTML-like markup language. The disadvantage is that pages are becoming harder and more obscure to design and maintain, as it becomes more sophisticated.
Browsers that support Ajax
(Note that this is a general list, and support of Ajax applications will depend on the features the browser supports.)
- Microsoft Internet Explorer version 5.0 and above, and browsers based on it (Mac OS versions not supported)
- Gecko-based browsers like Mozilla, Mozilla Firefox, SeaMonkey, Epiphany (web browser), Galeon and Netscape version 7.1 and above
- Browsers implementing the KHTML API version 3.2 and above, including Konqueror version 3.2 and above, and Apple Safari version 1.2 and above
- Opera browsers version 8.0 and above, including Opera Mobile Browser version 8.0 and above
- iCab version 3.0b352 and above
Browsers that do not support Ajax
This is a list of browsers that definitely do not support Ajax
- Opera 7 and below
- Microsoft Internet Explorer 4.0 and below
- Text-based browsers like Lynx and Links
- Browsers for the visually impaired (speech-synthesising, braille)
- Browsers made before 1997
See also
- Rich Internet Application
- Single Page Application
- Client/SOA
- Progressive Enhancement
- Graceful degradation
- Open Ajax
- AjaXSLT
- Sajax
External links
Articles
- Ajax: A New Approach to Web Applications, by Jesse James Garrett. The original article which coined the term.
- Why Ajax Matters Now by Jesse James Garrett.
- Weighing the Alternatives How Ajax stacks up against competing RIA approaches.
- Ajax community portal AjaxToday.com, ajax community portal for the ajax developers.
Tutorials
- AJAX:Getting Started by Mozilla Developer Center.
- Building AJAX web page
- Dynamic HTML and XML: The XMLHTTPRequest Object by Apple.
- Cross-browser Ajax Tutorial using the Sarissa library.
- JavaScript refactoring for safer, faster, better Ajax.
- ASP.NET Spiced: AJAX from MSDN.
- Mastering Ajax Introduction to Ajax part 1, 2, 3.
- Ajax Patterns: Ajax Fundamentals and Programming/Usability Patterns