Thursday, September 21, 2006

Ajax, at last. But will it?

I have finally made my own prototype of an ajax site. So be it, that it is my very own personal site. Made only to merchandise myself, but still. It took some time get get all the components in line but I finally made it work, using some reverse enginering then of course. It is the best way to learn and anyone who says otherwise haven't coded in a hurry before. The ajax components of the site are as follows: an XML menu, which then of course is aquired asynchronosly. Bit unecessary perhabs. Might have been better to this in a more asp friendly solution but this way WAS more fun. Content for the main event area is pulled from text documents containing the relevant code for that specific page. When I finally stripped the code I realised how little was needed for the actual pulling. As soon as the XMLHttpRequest() object had been defined the really wasn't anything left to do but defining this handy little function:

function processPage(url) {

if (xmlHttp)
{
try
{
xmlHttp.open("GET", url, true);
xmlHttp.onreadystatechange = handleRequestStateChange;
xmlHttp.send(null);
}
catch(e)
{
alert("Can't connect to server:\n "+e.toString());
}
}
}

Well well, we will see how this unfolds. There are probebly better ways to do this but, You have to fall before you can learn to walk. At least the floor won't come as such a suprise if you rather do it later than earlier...

No comments: