Ajax (programming)
From Wikipedia, the free encyclopedia
Ajax, or AJAX (Asynchronous JavaScript and XML), is a group of interrelated web development techniques used to create interactive web applications or rich Internet applications. With Ajax, web applications can retrieve data from the server asynchronously in the background without interfering with the display and behavior of the existing page. The use of Ajax has led to an increase in interactive animation on web pages.[1][2] Data is retrieved using the XMLHttpRequest object or through the use of Remote Scripting in browsers that do not support it. Despite the name, the use of JavaScript and XML is not actually required, nor do the requests need to be asynchronous.[3] The acronym AJAX has thus changed to the term Ajax, which does not represent these specific technologies.[4]
Contents |
[edit] History
While the term "Ajax" was coined in 2005,[5] alternative techniques for the asynchronous loading of content date back to the mid 1990s. Java applets were introduced in the first version of the Java language in 1995. These allow compiled client-side code to load data asynchronously from the web server after a web page is loaded.[6] In 1996, Internet Explorer introduced the IFrame element to HTML, which also enables this to be achieved.[7] In 1999, Microsoft created the XMLHTTP ActiveX control in Internet Explorer 5. This is now supported by Mozilla, Safari and other browsers as the native XMLHttpRequest object.[7][8] On April 5, 2006 the World Wide Web Consortium (W3C) released the first draft specification for the object in an attempt to create an official web standard.[9]
[edit] Technologies
The term Ajax has come to represent a broad group of web technologies that can be used to implement a web application that communicates with a server in the background, without interfering with the current state of the page. In the article that coined the term Ajax,[5] Jesse James Garrett explained that the following technologies are required:
- XHTML and CSS for presentation
- the Document Object Model for dynamic display of and interaction with data
- XML and XSLT for the interchange, manipulation and display of data, respectively
- the XMLHttpRequest object for asynchronous communication
- JavaScript to bring these technologies together
Since then, however, there have been a number of developments in the technologies used in an Ajax application, and the definition of the term Ajax. In particular, it has been noted that:
- JavaScript is not the only client-side scripting language that can be used for implementing an Ajax application. Other languages such as VBScript are also capable of the required functionality.[3]
- XML is not required for data interchange and therefore XSLT is not required for the manipulation of data. JavaScript Object Notation (JSON) is often used as an alternative format for data interchange,[10] although other formats such as preformatted HTML or plain text can also be used.[11]
[edit] Critique
[edit] Advantages
- In many cases, related pages on a website consist of much content that is common between them. Using traditional methods, that content would have to be reloaded on every request. However, using Ajax, a web application can request only the content that needs to be updated, thus drastically reducing bandwidth usage and load time.[12]
- The use of asynchronous requests allows the client's Web browser UI to be more interactive and to respond quickly to inputs, and sections of pages can also be reloaded individually. Users may perceive the application to be faster or more responsive, even if the application has not changed on the server side.[13]
- The use of Ajax can reduce connections to the server, since scripts and style sheets only have to be requested once.[13]
- State can be maintained throughout a Web site. JavaScript variables will persist because the main container page need not be reloaded.
[edit] Disadvantages
- Pages dynamically created using successive Ajax requests do not automatically register themselves with the browser's history engine, so clicking the browser's "back" button may not return the user to an earlier state of the Ajax-enabled page, but may instead return them to the last full page visited before it. Workarounds include the use of invisible IFrames to trigger changes in the browser's history and changing the anchor portion of the URL (following a #) when AJAX is run and monitoring it for changes.[13]
- Dynamic web page updates also 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 '#') to keep track of, and allow users to return to, the application in a given state.[13]
- Because most web crawlers do not execute JavaScript code,[citation needed] web applications should provide an alternative means of accessing the content that would normally be retrieved with Ajax, to allow search engines to index it.
- Any user whose browser does not support Ajax or JavaScript, or simply has JavaScript disabled, will not be able to use its functionality. Similarly, devices such as mobile phones, PDAs, and screen readers may not have support for JavaScript or the XMLHttpRequest object.[citation needed] Also, screen readers that are able to use Ajax may still not be able to properly read the dynamically generated content.[14] The only way to let the user carry out functionality is to fall back to non-JavaScript methods. This can be achieved by making sure links and forms can be resolved properly and rely not solely on Ajax. In JavaScript, form submission could then be halted with "return false".[15]
- The same origin policy prevents some Ajax techniques from being used across domains,[16] although the W3C has a draft that would enable this functionality.[17]
- Ajax opens up another attack vector for malicious code that web developers might not fully test for.[18][19]
[edit] See also
- AJAST (programming)
- Ajax framework
- Comet (programming)
- Reverse Ajax
- Rich Internet application
- XMLHttpRequest
[edit] Notes
- ^ Moore, John (2008-07-07). "What is Ajax?". RIAspot.com. http://www.riaspot.com/articles/entry/What-is-Ajax-. Retrieved on 2008-07-07.
- ^ Hope, Paco; Walther, Ben (2008), Web Security Testing Cookbook, O'Reilly Media, Inc., ISBN 978-0-596-51483-9
- ^ a b Ullman, Chris (March 2007). Beginning Ajax. wrox. ISBN 978-0-470-10675-4. http://www.wrox.com/WileyCDA/Section/id-303217.html. Retrieved on 2008-06-24.
- ^ Richardson, Leonard; Ruby, Sam (2007). RESTful Web Services. pp. 315-316.
- ^ a b Jesse James Garrett (2005-02-18). "Ajax: A New Approach to Web Applications". AdaptivePath.com. http://www.adaptivepath.com/ideas/essays/archives/000385.php. Retrieved on 2008-06-19.
- ^ "Code Samples and Apps: Applets". Sun Microsystems, Inc.. http://java.sun.com/applets/. Retrieved on 2009-01-02.
- ^ a b Hinchcliffe, Dion (June 2006). Real-World Ajax: Secrets of the Masters. SYS-CON Media. ISBN 9780977762200. http://ajaxdevelopersjournal.com/read/338113.htm.
- ^ "Dynamic HTML and XML: The XMLHttpRequest Object". Apple Inc. http://developer.apple.com/internet/webcontent/xmlhttpreq.html. Retrieved on 2008-06-25.
- ^ "The XMLHttpRequest Object". World Wide Web Consortium. 2006-04-05. http://www.w3.org/TR/2006/WD-XMLHttpRequest-20060405/. Retrieved on 2008-16-25.
- ^ "JSON - JavaScript Object Notation". Apache.org. http://tapestry.apache.org/tapestry4.1/ajax/json.html. Retrieved on 2008-07-04.
- ^ "Speed Up Your AJAX-based Apps with JSON". DevX.com. http://www.devx.com/webdev/Article/32651. Retrieved on 2008-07-04.
- ^ Merrill, Christopher (2006-01-15). "Performance Impacts of AJAX Development". Web Performance, Inc. http://www.webperformanceinc.com/library/reports/AjaxBandwidth/. Retrieved on 2008-06-16.
- ^ a b c d "Why use AJAX?". InterAKT. 2005-11-10. http://www.interaktonline.com/support/articles/Details/AJAX:+Asynchronously+Moving+Forward-Why+use+AJAX%3F.html?id_art=36&id_asc=309. Retrieved on 2008-06-26.
- ^ Edwards, James (2006-05-05). "AJAX and Screenreaders: When Can it Work?". sitepoint.com. http://www.sitepoint.com/article/ajax-screenreaders-work. Retrieved on 2008-06-27.
- ^ Quinsey, Peter. "User-Proofing Ajax". http://www.alistapart.com/articles/userproofingajax.
- ^ "Access Control for Cross-Site Requests". World Wide Web Consortium. http://dev.w3.org/2006/waf/access-control/. Retrieved on 2008-06-27.
- ^ Sullivan, Bryan. "Testing for security in the age of AJAX Programming". developerFusion. http://www.developerfusion.com/article/6197/testing-for-security-in-the-age-of-ajax-programming/. Retrieved on 2008-10-15.
- ^ Stamos, Alex; Lackey, Zane. "Attacking AJAX Web Applications". iSEC Partners. http://www.isecpartners.com/files/iSEC-Attacking_AJAX_Applications.BH2006.pdf. Retrieved on 2009-04-02.
[edit] External links
- Ajax: A New Approach to Web Applications
- Ajax (programming) at the Open Directory Project
- Ajax Tutorial with get, post, text and XML examples.