an ordinary blog — andr3.net

rss feed

my lifestream rss feed

are you tired of this? then return to latest posts

My first steps in AJAX

First Steps in AjaxI had to start sometime, given my past experiences with Javascript, but i had to get some stuff out of the way first – namely, this website – so that i could dedicate an evening messing around with this new technique – not technology – without other stuff in my head.

It wasn't hard to pick up and i was a bit surprised by the simplicity of it all. I had some issues putting it to work, but that was mostly due to the fact i was working on a computer without access to the internet, thus no google for me. I figured it out in the end, and put together a very simple page which basically asks for an XML file through AJAX, handles it and displays it on the page – i still need to check if XSLT works in this environment.


Here's an example of an XML file:

helloworld.xml

<sentence>
    <word>Hello</word>
    <word spaced="false">World</word>
    <word spaced="false">!</word>
</sentence>


To complicate things a little, i had an attribute named spaced which when set to false means that the word is not supposed to be followed by a space. I know that semantically speaking, it's not a very correct XML structure... the punctuation sign ! is not a word, but hey... this is just a test. ;)

This file should display the obvious message:

Hello World!


A final note

Just like every other over-hyped techniques, AJAX can be misused, but if used right... its potential is enormous. Also, accessibility should not be forgotten, actually, it should be even more important. If you're performing a critical operation through AJAX, make sure it can also be performed by users without Javascript support.

Test it

I have tested it on Mozilla Firefox 1.0.6 and Internet Explorer 6.0, both on Windows XP. If you run into any bugs, let me know in the comments. I don't want to start with browser incompatibilities. ;) Thanks.

Here's the link:
workshop.andr3.net/ajax-firststeps

Related files

Feel free to have a peek at the files. It's no break-through, but it might help, if you're trying to get started.

  • ajax.js
    this file has the functions related to the XMLHttpRequest Object. Initializing, sending request and showing debug messages.
  • helloworld.js
    this one is in charge of starting the whole deal.

Related link


Next? Hmmm... i'm thinking of an XML based picture gallery... It could be a good exercise on the subject, i don't know.

Comments

↑ top