.. _quickstart/ajax: AJAX and Dojo ============= :Status: Draft :Version: 1.0 :Authors: Nikolai Onken, Craig Riecke .. contents:: :depth: 2 Ajax has been a buzzword around for some time now (as far as you could call some time a lot of time ;) ) and is one of the concepts which have changed the development for the web quite drastically. Dojo provides a solid set of battle-tested XHR wrapper functions to allow you to build Ajax interactions with confidence, use a unified API, and handle forms with ease. These APIs are built into Dojo Base, so you can use them in any page that includes dojo.js. Read on to learn how easy it is to build powerful Ajax interactions with Dojo. The XMLHTTP request object (XHR for short) is one of the basic building blocks for constructing responsive Ajax-drive interactions. By allowing you to retrieve data on the user's behalf without refreshing the whole page the XHR object provides tremendous, but cross-browser XHR usage is beset by memory leaks, divergent APIs, a lack of built-in form encoding from JavaScript, and painful corner cases when de-serializing response data. =========== XHR Options =========== All `XHR` functions follow the same pattern in the `property-bag` configuration options, passed to whichever function is called. They include: * url - the endpoint to connect to and load data from. This must be on the same host and port as the serving page, a security limitation of XHR. * handleAs - describes which formatter to use on the incoming data. Defaults to 'text', so any response data comes back as a plain string. Available options out of the box are: "json" (to convert the data to a JSON object), "javascript" (to load and execute JS fragments), "json-comment-optional" (to deprecate warnings about the poor security of client-side JSON parsing) and xml. * timeout - a time in MS to wait before giving up the XHR call, and throwing an error to the error callback. * sync - a boolean to determine if the XHR call should be synchronous or asynchronous. Setting sync:true will cause the browser to stop the chain of execution until the data is returned. Defaults to ``false``. * form - a DOM Node of a ``