Jump to content

Ajax (programming)

From Wikipedia, the free encyclopedia

This is an old revision of this page, as edited by Quilokos (talk | contribs) at 18:24, 26 July 2009 (→‎Critique). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

Ajax, sometimes written as AJAX (shorthand for asynchronous JavaScript and XML), is a group of interrelated web development techniques used on the client-side 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] and better quality of Web services due to the asynchronous mode. Data is usually retrieved using the XMLHttpRequest object. Despite the name, the use of JavaScript and XML is not actually required, nor do the requests need to be asynchronous.[3]

Constituent technologies

Like DHTML and LAMP, Ajax is not a technology in itself, but a term that refers to the use of 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 <script> 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.

History

Jesse James Garrett thought of the term "Ajax" while in the shower,[4] when he realized the need for a shorthand term to represent the suite of technologies he was proposing to a client.[5] While the term was coined in 2005,[6] 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.[7] In 1996, Internet Explorer introduced the IFrame element to HTML, which also enables this to be achieved.[8] 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.[8][9] 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.[10]

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,[6] Jesse James Garrett explained that the following technologies are required:

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,[11] although other formats such as preformatted HTML or plain text can also be used.[12]

Rationale

  • 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.[13]
  • 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.[14]
  • The use of Ajax can reduce connections to the server, since scripts and style sheets only have to be requested once.[14]
  • State can be maintained throughout a Web site. JavaScript variables will persist because the main container page need not be reloaded.

Critique

  • 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.[14]
  • 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.[14]
  • Because most web crawlers do not execute JavaScript code,[15] publicly indexable 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. Also, screen readers that are able to use Ajax may still not be able to properly read the dynamically generated content.[16] 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".[17]
  • The same origin policy prevents some Ajax techniques from being used across domains,[10] although the W3C has a draft that would enable this functionality.[18]
  • Ajax opens up another attack vector for malicious code that web developers might not fully test for.[19][20]

See also

Notes

  1. ^ Moore, John (2008-07-07). "What is Ajax?". RIAspot.com. Retrieved 2008-07-07.
  2. ^ Hope, Paco; Walther, Ben (2008), Web Security Testing Cookbook, Sebastopol, CA: O'Reilly Media, Inc., ISBN 978-0-596-51483-9
  3. ^ a b Ullman, Chris (2007). Beginning Ajax. wrox. ISBN 978-0-470-10675-4. Retrieved 2008-06-24. {{cite book}}: Unknown parameter |month= ignored (help)
  4. ^ "New Web-based Technology Draws Applications, Investors". Wall Street Journal. 2005-11-03. Retrieved 2006-06-14.
  5. ^ At subsequent talks and seminars Garrett has made the point that Ajax is not an acronym.
  6. ^ a b Jesse James Garrett (2005-02-18). "Ajax: A New Approach to Web Applications". AdaptivePath.com. Retrieved 2008-06-19.
  7. ^ "Code Samples and Apps: Applets". Sun Microsystems, Inc. Retrieved 2009-01-02.
  8. ^ a b Hinchcliffe, Dion (2006). Real-World Ajax: Secrets of the Masters. SYS-CON Media. ISBN 9780977762200. {{cite book}}: Unknown parameter |month= ignored (help)
  9. ^ "Dynamic HTML and XML: The XMLHttpRequest Object". Apple Inc. Retrieved 2008-06-25.
  10. ^ a b "The XMLHttpRequest Object". World Wide Web Consortium. 2006-04-05. Retrieved 2008-16-25. {{cite web}}: Check date values in: |accessdate= (help)
  11. ^ "JSON - JavaScript Object Notation". Apache.org. Retrieved 2008-07-04.
  12. ^ "Speed Up Your AJAX-based Apps with JSON". DevX.com. Retrieved 2008-07-04.
  13. ^ Merrill, Christopher (2006-01-15). "Performance Impacts of AJAX Development". Web Performance, Inc. Retrieved 2008-06-16.
  14. ^ a b c d "Why use AJAX?". InterAKT. 2005-11-10. Retrieved 2008-06-26.
  15. ^ Prokoph, Andreas (2007-05-08). "Help Web crawlers efficiently crawl your portal sites and Web sites". IBM. Retrieved 2009-04-22.
  16. ^ Edwards, James (2006-05-05). "AJAX and Screenreaders: When Can it Work?". sitepoint.com. Retrieved 2008-06-27.
  17. ^ Quinsey, Peter. "User-Proofing Ajax".
  18. ^ "Access Control for Cross-Site Requests". World Wide Web Consortium. Retrieved 2008-06-27.
  19. ^ Sullivan, Bryan. "Testing for security in the age of AJAX Programming". developerFusion. Retrieved 2008-10-15.
  20. ^ Stamos, Alex. "Attacking AJAX Web Applications" (PDF). iSEC Partners. Retrieved 2009-04-02. {{cite web}}: Unknown parameter |coauthors= ignored (|author= suggested) (help)

External links