Ajax (programming)

From LIMSWiki
(Redirected from Ajax)
Jump to navigationJump to search

Ajax (also AJAX) is a group of interrelated Web development techniques used on the client-side to create asynchronous Web applications. With Ajax, Web applications can send data to and retrieve data from a server asynchronously (in the background) without interfering with the display and behavior of the existing page. Data can be retrieved using the XMLHttpRequest object and API (application programming interface). Despite the name, the use of XML is not required; JavaScript Object Notation (JSON) is often used instead, and the requests do not need to be asynchronous.[1]

Ajax is a group of technologies. HTML and CSS can be used in combination to mark up and style information. The Document Object Model (DOM) is accessed with JavaScript to dynamically display – and allow the user to interact with – the information presented. JavaScript and the XMLHttpRequest object provide a method for exchanging data asynchronously between browser and server to avoid full page reloads.

History

In the 1990s, most websites were based on complete HTML pages. Each user action required a complete page be loaded from the server. This process was inefficient, as reflected by the user experience: all page content disappeared, then reappeared. Each time the browser reloaded a page because of a partial change, all of the content had to be re-sent, even though only some of the information had changed. This placed additional load on the server and used excessive bandwidth. Later in the mid- to late '90s, Microsoft began updating its Internet Explorer browser to better handle content asynchronously, including the introduction of the iframe tag in 1996, the first XMLHTTP component in 1998, and an XMLHTTP ActiveX control in 1999 that years later was adopted by Mozilla, Safari, Opera, and other browsers as the XMLHttpRequest JavaScript object.[2]

By the mid-2000s, the idea of using XML within HTTP requests began to truly take shape. Microsoft had already worked on adding this sort of functionality into its Outlook Web Access for Exchange in the early 2000s, and Google followed suit with it Gmail and Google Maps products in 2004 and 2005 respectively.[3][4][5] And in October 2004 the public beta release of Kayak.com was among the first large-scale e-commerce applications of the technology, what their developers at that time called "the xml http thing."[6] The set of technologies would formally stick with the name "Ajax," an acronym for "asynchronous JavaScript and XML," and be described by Adaptive Path's founder and president Jesse James Garrett in February 2005 as "several technologies, each flourishing in its own right, coming together in powerful new ways."[5][1]

On April 5, 2006, the World Wide Web Consortium (W3C) released the first draft specification for the Ajax XMLHttpRequest object in an attempt to create an official Web standard.[7] The standard was created, and as of August 2014 it is still maintained by the W3C.[8]

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," Jesse James Garrett explained the incorporated technologies[5]:

  • HTML (or XHTML) and CSS for presentation
  • The Document Object Model (DOM) for dynamic display of and interaction with data
  • XML for the interchange of data, and XSLT for its manipulation
  • 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. XML is not required for data interchange and XSLT is not required for the manipulation of data. |JavaScript Object Notation (JSON) is often used as an alternative format for data interchange[9], although other formats such as pre-formatted HTML or plain text can also be used.[10]

Drawbacks

Some web developers have identified drawbacks to using Ajax, past and present. Examples include:

  • In pre-HTML5 browsers, pages dynamically created using successive Ajax requests did not automatically register themselves with the browser's history engine, so clicking the browser's "back" button may not have returned the browser to an earlier state of the Ajax-enabled page. Instead, it may have returned to the last full page visited before it. Such behavior — navigating between pages instead of navigating between page states — may be desirable, but if fine-grained tracking of page state is required, then a pre-HTML5 workaround used invisible iframes to trigger changes in the browser's history. A workaround implemented by Ajax techniques is to change the URL fragment identifier (the part of a URL after the "#") when an Ajax-enabled page is accessed and monitor it for changes.[11][12] HTML provides an extensive API standard for working with the browser's history engine.[13]
  • Dynamic Web page updates also make it difficult to bookmark and return to a particular state of the application. Solutions to this problem exist, many of which again use the URL fragment identifier.[11][12] The solution provided by HTML5 for the above problem also applies for this.[13]
  • Depending on the nature of the Ajax application, dynamic page updates may interfere disruptively with user interactions, especially if working on an unstable Internet connection. For instance, editing a search field may trigger a query to the server for search completions, but the user may not know that a search completion pop-up is forthcoming. If the Internet connection is slow, the pop-up list may show up at an inconvenient time, when the user has already proceeded to do something else.
  • Most Web crawlers do not execute JavaScript code[14], so in order to be indexed by search engines, a Web application must provide an alternative means of accessing the content that would normally be retrieved with Ajax.
  • Any user whose browser does not support JavaScript or XMLHttpRequest, or simply has this functionality disabled, will not be able to properly use pages which depend on Ajax. Devices such as smartphones may not have support for the required technologies, though this is becoming less of a problem. 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 not relying solely on Ajax.[15]
  • Similarly, some Web applications that use Ajax are built in a way that cannot be read by screen-reading technologies, such as JAWS. The WAI-ARIA standards provide a way to provide hints in such a case.[16]
  • Screen readers that are able to use Ajax may still not be able to properly read the dynamically generated content.[17]
  • The same-origin policy prevents some Ajax techniques from being used across domains[7], although the W3C has a draft of the XMLHttpRequest object that would enable this functionality.[18] Methods exist to sidestep this security feature by using a special Cross Domain Communications channel embedded as an iframe within a page[19] or by the use of JSONP.
  • The asynchronous callback-style of programming required can lead to complex code that is hard to maintain, to debug[20], and to test.[21] If your page uses a lot of Ajax on load, then WebDriver may not know when it has completely loaded. If you need to ensure such pages are fully loaded, then you can use explicit and implicit waits.[22]

External links

Notes

Numerous elements of this article are reused from the Wikipedia article.

References

  1. 1.0 1.1 Ullman, Chris (March 2007). Beginning Ajax. Wrox. ISBN 9780470106754. Archived from the original on 05 July 2008. https://web.archive.org/web/20080705101852/http://www.wrox.com/WileyCDA/Section/id-303217.html. Retrieved 18 August 2014. 
  2. "Dynamic HTML and XML: The XMLHttpRequest Object". Apple Inc. 24 June 2014. Archived from the original on 05 March 2011. https://web.archive.org/web/20110305043442/http://developer.apple.com/internet/webcontent/xmlhttpreq.html. Retrieved 18 August 2014. 
  3. Microsoft Exchange Team (21 June 2005). "Outlook Web Access - A catalyst for web evolution". Microsoft. http://blogs.technet.com/b/exchange/archive/2005/06/21/406646.aspx. Retrieved 18 August 2014. 
  4. Swartz, Aaron (22 December 2005). "A Brief History of Ajax". Raw Thought. http://www.aaronsw.com/weblog/ajaxhistory. Retrieved 18 August 2014. 
  5. 5.0 5.1 5.2 Garrett, Jesse James (18 February 2005). "Ajax: A New Approach to Web Applications". Adaptive Path. Archived from the original on 02 July 2008. https://web.archive.org/web/20080702075113/http://www.adaptivepath.com/ideas/essays/archives/000385.php. Retrieved 18 August 2014. 
  6. English, Paul (12 April 2006). "Kayak User Interface". Official Kayak.com Technoblog. Kayak.com. http://kayaklabs.blogspot.com/2006/04/kayak-user-interface.html. Retrieved 18 August 2014. 
  7. 7.0 7.1 "The XMLHttpRequest Object". World Wide Web Consortium. 5 April 2006. Archived from the original on 16 May 2008. https://web.archive.org/web/20080516060525/http://www.w3.org/TR/2006/WD-XMLHttpRequest-20060405/. Retrieved 18 August 2014. 
  8. "XMLHttpRequest Living Standard". W3C. 12 August 2014. http://xhr.spec.whatwg.org/. Retrieved 18 August 2014. 
  9. "JSON - JavaScript Object Notation". Apache Software Foundation. 12 February 2008. Archived from the original on 16 June 2008. https://web.archive.org/web/20080616113121/http://tapestry.apache.org/tapestry4.1/ajax/json.html. Retrieved 18 August 2014. 
  10. Lacava, Alessandro (5 October 2006). "Speed Up Your Ajax-based Apps with JSON". DevX.com. Jupitermedia Corporation. Archived from the original on 04 July 2008. https://web.archive.org/web/20080704134131/http://www.devx.com/Webdev/Article/32651. Retrieved 18 August 2014. 
  11. 11.0 11.1 "Why use AJAX?". InterAKT. 10 November 2005. Archived from the original on 29 May 2008. https://web.archive.org/web/20080529080808/http://www.interaktonline.com/support/articles/Details/AJAX:+Asynchronously+Moving+Forward-Why+use+AJAX%3F.html?id_art=36&id_asc=309. Retrieved 26 June 2008. 
  12. 12.0 12.1 Li, Andy (8 April 2009). "Deep Linking for AJAX". Andy Li's Blog. http://blog.onthewings.net/2009/04/08/deep-linking-for-ajax/. Retrieved 18 August 2014. 
  13. 13.0 13.1 "7.5 Session history and navigation". HTML Specification. WHATWG. 6 August 2014. http://www.whatwg.org/specs/web-apps/current-work/multipage/browsers.html#history. Retrieved 18 October 2014. 
  14. Prokoph, Andreas (8 May 2007). "Help Web crawlers efficiently crawl your portal sites and Web sites". developerWorks. IBM. http://www.ibm.com/developerworks/library/x-sitemaps/index.html. Retrieved 18 August 2014. 
  15. Quinsey, Peter (5 December 2006). "User-Proofing Ajax". A List Apart. http://www.alistapart.com/articles/userproofingajax. Retrieved 18 August 2014. 
  16. Henry, Shawn Lawton (September 2010). "WAI-ARIA Overview". W3C. Archived from the original on 26 October 2010. https://web.archive.org/web/20101026062837/http://www.w3.org/WAI/intro/aria.php. Retrieved 18 August 2014. 
  17. Edwards, James (5 May 2006). "Ajax and Screenreaders: When Can it Work?". SitePoint. http://www.sitepoint.com/ajax-screenreaders-work/. Retrieved 18 August 2014. 
  18. "Cross-Origin Resource Sharing". W3C. 11 June 2012. https://dvcs.w3.org/hg/cors/raw-file/tip/Overview.html. Retrieved 18 August 2014. 
  19. Thorpe, Danny (July 2007). "Secure Cross-Domain Communication in the Browser". The Architecture Journal. Microsoft. http://msdn.microsoft.com/en-us/library/bb735305.aspx. Retrieved 18 August 2014. 
  20. Cuthbertson, Tim (4 July 2010). "What is asynchronous programming, and why is it so damn awkward?". defer: Taming asynchronous javascript with CoffeeScript. http://gfxmonk.net/2010/07/04/defer-taming-asynchronous-javascript-with-coffeescript.html#1. Retrieved 18 August 2014. 
  21. "Selenium-WebDriver API Commands and Operations". Selenium WebDriver. Selenium Project. 31 July 2014. http://seleniumhq.org/docs/03_webdriver.html#fetching-a-page. Retrieved 18 August 2014. 
  22. "WebDriver: Advanced Usage". Selenium WebDriver. Selenium Project. 31 July 2014. http://docs.seleniumhq.org/docs/04_webdriver_advanced.jsp. Retrieved 18 August 2014.