Saturday, October 20, 2007

AJAX, c'ntd.

Since I spent all of Wed. and Thurs. evenings working on my little Ajax problem, I decided I was going to take the night off and go out for a bit. Naturally, this is when it decided to rain. It didn't just rain, though-- it rained sideways because of the heavy winds.

So, I wound up staying home and eventually got back to the ajax project. The back end piece is all done. I've got the mySQL database set up, with a lame little database table of red wines and associated info in it. I've got php talking to it, so my little web app can query the database and show results. It even sends the results back in XML.

Now that the back end is complete, it was time to focus on the client side of things. I'd been reading good things about some of the extra features of AJAX frameworks (e.g. Prototype and Dojo), so rather than go with the bare bones implementation of AJAX code I got from the class, I decided to download and use the Prototype framework instead. Nothing against Dojo, it's just that more third party tools seemed to use Prototype than Dojo, such as OpenRico.

"Installing" Prototype on my web page (more like including it, actually) was pretty straightforward and easy. I had to modify my thinking a bit from what I learned and did in the actual class (e.g. creating the object "up front" and then passing info along at a later point), but I wound up being able to send my request via Javascript in the background, getting an XML response, and then displaying it in a Javascript alert on the client. I still need to write some Javascript (wines.js) to handle the unique code for this application, but I'm almost done with it. Of course, I've saved the most difficult (for me, that is) part for last-- using Javascript to manipulate the web browser's Document Object Model, aka DOM, for short.

I've always hated working with the DOM. I think a lot of my frustration has been that different browsers had different models, and you had to check each one you looked at to figure out how to work it properly. The good news is that the models have moved closer to being standard, and with the getElementById function in Javascript I no longer have to worry as much about where in the tree a particular element lies.