« CTO Breakfast | Main | Debunking SAML Myths and Misunderstandings »
More on XMLHttpRequest
Bill Bercik has a nifty little tutorial on using XMLHttpRequest. His purpose is “to demonstrate through a series of baby steps just how easy it is to use the XMLHttpRequest object.” The example is a simple form that fills in, using XMLHttpRequest, the city and state after you type the zip code. He does it in seven steps:
- Create the form
- Add the event handler
- Create the XMLHttpRequest Object
- Talk to the server using an HTTP GET
- Build the zip-code database
- Build a PHP handler to respond to the GET request and return the right values from the DB.
- Clean up the code to handle exceptions
There’s no need to use XML in this simple example, but he shows how to do it anyway, since more complex examples will need it.
The trick to XMLHttpRequest is that it has a method, onreadystatechange that lets you register a function to handle the return request. So, the event handler fires off the HTTP request and then the code sits back and waits for the response. Once you know how to create the XMLHttpRequest object (and that’s mostly cut and paste) and see how to use it, the rest is pretty straightforward.
Posted by windley on February 25, 2005 9:03 AM




Comment from Sam Curren at February 25, 2005 10:17 AM
While XMLHttpRequest does do the trick, I've become a fan of using the hidden iFrame trick to do server round-trips. My favorite method uses a JS api that makes it painfully easy:
http://www.pengoworks.com/workshop/js/gateway/index.cfm
Comment from Mr. Wobbet at March 1, 2005 8:50 AM
Looking at GMail and Google Maps have really gotten under my skin to look more into this. I haven't done anything with it yet but in addition to Ajax I also found this on the O'Reilly Network (XML.COM to be specific).
http://www.xml.com/pub/a/2005/02/23/sarissa.html
Sarissa is a browser, and apparently platform, independent ECMAScript library for doing just this sort of stuff.
Nifty!
With this and your links to "The Little Schemer" I'm really worked up about coding again. Now if I could just find time with my two-week old son...
rjsjr