Before I get started with my usual ramblings, I'd like you to take a look at Googles latest toy, found at http://www.google.com/webhp?complete=1&hl=en.
It's using the XMLHTTP-object to fetch data without reloading the page, offering suggestions as you type as to other searches that might be related to yours.
I really like Google, they try things without the "look at me"-factor that are common with most, if not all, DHTML-applications that know that they are doing something new. This is a very useful application, plain and simple, that makes absolutly no fuzz about it being that. - It's downright sneaky that way, and it's as clean and simplistic as any other of Googles services, and it's the sort of thing that feels absolutly natural when you use it. I could'nt even belive that I'd never come across it before, and it actually took me a few seconds to realize what the heck was new about it to begin with.
This has been the main point of Google from the get-go, focus, keeping the user and the service firmly aligned, and making sure nothing get's in the way of that relationship.
But a developer can't help thinking that this is really cool, wondering if there's a simpler way of
doing it? - Of course there is simpler way.
XML makes it very easy infact, the "to inject suggestions as you type" part that is, but I need to point out from the get-go, that you can't beat what lies at the heart of this app, namely the search-technology that is Google. It's easy to set up the line of communication that adds the suggestion-box and fills it with data, but the real value of the service has to do with what data
But that said, using XML allows us to do the same,
with even less code than Googles own implementation.
As I'm a Naltabyte-guy, so I use miopages for this, and I simply use the fact that miopages are as interactive as dhtml, and the fact that the first response from the server is set as html, but all the following responses are set as XML, while still being the same code. Then I can reload the responses as XML into the same page, using the XMLHTTP-object. This might seem messy, but it's all coming down to a few lines of code.
This experiment is simply counting the character-length of what you type, and returns the
result to the box appearing under the text-field while you type it in. (This is so, because I dont have a big hunking search-technology like Google does. If I did, you think I would be here, writing this? Nah, I'd probably be sailing the westindies, sipping a cool drink with a bunch of babes..)
/* The first response is HTML, the second is XML.*/
/* This function is called from the client as you
type, and the 'str' is what you typed. */
The length of: <i>"+str+"</i></div>");
The response.write() above returns a xml-formatted string, but using html-tags. This string is then added to the box after fetching.
This is the crux of the app, which can be found here:
The complete source for it is found here:
The app works in all the same browers that Googles app does, which is all browsers that supports the XMLHTTP-object. Opera doesn't yet, but they will beginning with the next release, according to their own statements.
Still, the real value here is a lesson for all of us developers. It might be a really simple effect, but it's still damn cool, and even more useful as a service.
It's obvious that services - in any sense of the word - is where it's at, and nothing does that better than XML does. It's also quite obvious that we will see many more of these implementations in the future - some from Google probably - being deceptivly simple, while also being insanely useful.
XML has clearly come about to meet the demand for services on all levels, enriching the web and making it more useful for ordinary everyday people.
The web seems to come of age at last..