XmlHttpRequest Object

With all the press that the XmlHttpRequest object has received lately, I thought I would check out what all the fuss was for myself.

I did a little research online, as you do and scoped out what it could and couldn’t do. From here, I started trying to do anything with it that made sense. Initially, this failed as I was trying to hit an RSS feed on this site from my home machine. This might seem like a logical thing to do, however the object is restricted to opening URL’s from the same domain. In my failed example, that would have been http://localhost/. You could get around that by mirroring a remote feed onto your particular domain using your favourite server side language.

Once I established that I could instance the objects and access a URL, it was time to start interacting with the content. The first attempt involved trying to access the information returned from the open method of the XML object. However, if you’re actually accessing XML data and not randomly formed SGML, you need to hit the responseXML property to return you an object you can interact with through the DOM. After assigning responseXML to a variable, you can now interact with it through the standard DOM methods, such as getElementById() and getElementsByTagName().

With that in mind, I set about creating something semi useful – an archive page for WordPress enhanced using XmlHttpRequest that would degrade gracefully should the XmlHttpRequest object not be available. To accomplish this, I utilised the existing feeds that WordPress provides, which are accessed through http://domain.com/<something>/feed/.

As soon as I get a little spare time, I’ll wrap it into a plugin and release it here.