Java Reference
In-Depth Information
Summary
This chapter introduced you to Ajax, and it barely scratched the surface of Ajax and its many uses.
You looked at the
XMLHttpRequest object, and how it differed between IE 5 & 6, and the other
browsers. You learned how to make both synchronous and asynchronous requests to the server
and how to use the onreadystatechange event handler.
You built your own Ajax module to make asynchronous HTTP requests easier for you to code.
You used our new Ajax module in a smarter form, one that checks user names and e-mails to
see if they are already in use.
You discussed how
XMLHttpRequest breaks the browser's Back and Forward buttons, and
addressed this problem by rebuilding the same form by using a hidden iframe to make requests.
You looked at some of the downsides to Ajax, the security issues and the gotchas.
Exercise Questions
Suggested solutions for these questions can be found in Appendix A.
1.
Extend the HttpRequest module to include synchronous requests in addition to the asynchro-
nous requests the module already makes. You'll have to make some adjustments to your code
to incorporate this functionality. (Hint: Create an async property for the module.)
2.
It was mentioned earlier in the chapter that the smart forms could be modifi ed to not use hyper-
links. Change the form that uses the HttpRequest module so that the user name and e-mail
fi elds are checked when the user submits the form. Use the form's onsubmit event handler and
cancel the submission if a user name or e-mail is taken. Also use the updated HttpRequest
module from Question 1 and use synchronous requests. The only time you need to alert the
user is when the user name or e-mail is taken, so make sure to return true if the user name
and e-mail pass muster.
Search WWH ::




Custom Search