At the Forge - Dojo Events and Ajax
Listing 3. hello.php
<? echo "Hello from the server!"; ?>
The button itself is defined as we might do with any button to which we expect to attach an event, with an id attribute. It sits inside of a very small HTML form, named “theForm”:
<form id="theForm"> <input type="button" id="theButton" value="Press here" /> </form>
Using Dojo events, we connect the button to a function (ajaxAlert):
Finally, our ajaxArgs object is bound, and we're off and running. Clicking on the button means the associated Dojo event is invoked, which is ajaxAlert. That function, thanks to dojo.io.bind, then sends its arguments to the defined URL and invokes the load function upon successful completion. This is surprisingly straightforward and opens up many possible avenues for using Ajax in applications.
The main source for information about Dojo, as well as Dojo software releases, is dojotoolkit.org. Documentation for the toolkit is still a bit sparse, but it has improved significantly in the last few months, and continued improvements seem likely, given Dojo's growing popularity. The main URL for Dojo documentation is at dojotoolkit.org/docs, and Dojo.book (the Wiki-based Dojo documentation) is at manual.dojotoolkit.org/index.html.
Finally, a noteworthy introduction to Dojo events is at www.dojotoolkit.org/docs/dojo_event_system.html.
Reuven M. Lerner, a longtime Web/database consultant, is a PhD candidate in Learning Sciences at Northwestern University in Evanston, Illinois. He currently lives with his wife and three children in Skokie, Illinois. You can read his Weblog at altneuland.lerner.co.il.
Practical books for the most technical people on the planet. Newly available books include:
- Agile Product Development by Ted Schmidt
- Improve Business Processes with an Enterprise Job Scheduler by Mike Diehl
- Finding Your Way: Mapping Your Network to Improve Manageability by Bill Childers
- DIY Commerce Site by Reven Lerner
Plus many more.
- diff -u: What's New in Kernel Development
- Server Hardening
- What's New in 3D Printing, Part III: the Software
- Giving Silos Their Due
- 22 Years of Linux Journal on One DVD - Now Available
- Controversy at the Linux Foundation
- Don't Burn Your Android Yet
- Firefox OS
- February 2016 Issue of Linux Journal