Baby’s first AJAX

I’ve enhanced my CoPilot Waypoint Database Generator to do a bit of AJAX-like coding.

Formerly, after you’d entered all your parameters it would fire off a background task, and then continually refresh a page that would look at the background task’s log file and tell you how many records it had put in the file already.

Now, the refresh page is still there, but if you have Javascript active, it does a window.location= to redirect to an html page which has some javascript that uses the XMLHttpRequest or ActiveXObject to call a perl script that generates a very small XML file that only has the progress, and sets the appropriate div in the page to visible and sets some values in appropriate spans.

It seems to work very nicely, but what a convoluted mess. Between the HTML, the CSS, the Perl, and the Javascript, I’ve got language fatigue. Javascript is not turning out to be my favourite language. I’ve never been able to understand why Sun didn’t sue Netscape over the intentional confusion between Java and Javascript, but now I’m even more confused.

All the other craptacular syntax and bogus object model aside, what Javascript really needs is a simple way to turn a simple bit of XML into an associative array. And don’t talk to me about JSON – even if I wrote both the client and the server, I just don’t feel right about having the client eval a string passed to it by the server – I just know there’s got to be a security exploit waiting to happen. So instead I’ve got all this

var tStatus = xmlDoc.getElementsByTagName("status")[0].firstChild.data;
var tOtherURL = xmlDoc.getElementsByTagName("otherurl")[0].firstChild.data;
var tRows = xmlDoc.getElementsByTagName("rows")[0].firstChild.data;

That's just ugly.