How This Book Is Organized


The book is divided into several chapters, organized by subject:


Chapter 1, Ajax Basics

What is Ajax? This chapter begins with a synopsis of the group of well-known technologies that make up Ajax. The chapter's hacks introduce the XMLHttpRequest JavaScript object and its properties and methods, then delve into the meat of the matter, such as sending GET and POST requests, as well as receiving data in plain text, XML, and JSON format. This chapter also illustrates the dynamic scripting of CSS styles in Ajax applications. Let the users change the colors and fonts inside the browser page!


Chapter 2, Web Forms

Web forms have certainly changed in the Ajax world. As revealed in this chapter's hacks, it is typical now to submit form data and to build form widgets such as select lists and checkbox groups using server data fetched in the background with XMLHttpRequest. Because the page doesn't have to be completely rebuilt from a server response, the user experiences few application delays. These hacks show how to submit text from form fields and textareas and display server values in those fields, without making the user click a submit button. The hacks also generate various elements, such as select lists and unordered lists, using XMLHttpRequest and data that is dynamically accessed from a server.


Chapter 3, Validation

Ajax applications can cut down on server hits by validating the format of email addresses, credit card numbers, zip codes, and other types of data that users enter into web forms before sending the data. A server component is obviously necessary for final credit card validation in a real-world application; however, the application may implement a "first layer of defense," as in these hacks, by validating the formats of text-field values with JavaScript regular expressions.


Chapter 4, Power Hacks for Web Developers

Web developers have never had cooler, easier-to-work-with tools than the Yahoo! and Google web APIs. This chapter includes a mash-up of Google Maps, Yahoo! Maps, and Yahoo! driving directions, as well as a software interaction involving Yahoo! Maps and a location-to-URL service called GeoURL. It also features more prosaic, pragmatic web hacks, such as sending an email with XMLHttpRequest; viewing, creating, and sending HTTP cookies with client-side script; fetching a postal code dynamically without altering the web page; as well as discovering and displaying the browser's locale information.


Chapter 5, Direct Web Remoting (DWR) for Java Jocks

DWR is a nifty toolkit that allows developers to make remote calls to Java server objects from JavaScript, without any Java applets or plug-ins. DWR uses Ajax requests behind the scenes; the toolkit's users, however, do not have to deal with XMLHttpRequest programming. These hacks populate select lists from Java arrays and Maps; call custom Java objects from their JavaScript proxies or counterparts; and use JavaScript objects to call built-in Java objects. This chapter is a treat for developers who are immersed in both Java and JavaScript.


Chapter 6, Hack Ajax with the Prototype and Rico Libraries

The hacks in this chapter use Prototype, a cool open source JavaScript library that includes its own Ajax tools. You'll see how to update DOM elements in a web page with server data using Prototype's Ajax.Updater object, and how to use the PeriodicalExecuter object to execute Ajax requests at timed intervals while another "observer" object monitors a text field for changes (imagine: a user enters data into text fields, and a JavaScript object automatically sends the data off to persistent server storage whenever the field value changes). Another hack in this chapter uses the open source library Rico in a Weather.com web services application. Finally, the chapter's last hack sets up a drag-and-drop bookstore, also using Rico.


Chapter 7, Work with Ajax and Ruby on Rails

Learn Ruby on Rails! Ruby on Rails (RoR) is an efficient and well-designed web application framework, based on the Model-View-Controller design pattern, that made its debut in 2005. This chapter begins with a simple hack that helps you get up and running with RoR, then moves on to several hacks that illustrate RoR's Ajax tools. Each hack is a web application task written in Ruby; for example, one of the hacks monitors a server connection and displays the status in the client. RoR bundles Prototype with the framework, then wraps the setup of the Ajax objects into its own easy-to-learn, embedded script language. Get ready to read a lot of Ruby code, a treat for those who may be new to this elegant and powerful tool!


Chapter 8, Savor the script.aculo.us JavaScript Library

script.aculo.us is another open source JavaScript library built on Prototype. It offers a broad menu of useful effects and controls for developers. These hacks create a Mac OS Xstyle login box that "shakes" in response to invalid logins; an auto-complete field based on a script.aculo.us object; a control that allows the user to edit textual content in the browser and then save the changes on a server, without a web page round trip; and, just for fun, a web form that disappears in a puff of smoke when it's submitted.


Chapter 9, Options and Efficiencies

These hacks provide several tips for real-world Ajax developers. Ironically, several hacks illustrate how to avoid using XMLHttpRequest to hit the server: you'll see how to run a search engine inside the browser, cache data with JavaScript, and "fix" the browser back button in an Ajax application by internally storing and accessing state. These hacks also recommend ways to combine code libraries to increase download speed, obfuscate or partially obscure JavaScript code to protect proprietary scripting, set a timer for aborting an Ajax request, as well as dynamically request data in JavaScript Object Notation (JSON) format using the HTML script tag.




Ajax Hacks
Ajax Hacks: Tips & Tools for Creating Responsive Web Sites
ISBN: 0596101694
EAN: 2147483647
Year: 2006
Pages: 138

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net