Wednesday, June 13, 2007

Minim takes wing

I've properly objectified and trimmed the minimal Ajax example I started work on earlier. It's now 336 bytes. My target is to keep the whole thing to under 2k, so I have 1712 bytes to put some other functions in.

It now looks like this:


function TinyAjax(callback) {
this._req = null;
this._sc = function() {
if (_req.readyState == 4 && _req.status == 200) {
callback(_req.responseText);
}
};

this.ajaxRequest = function(url) {
_req = new XMLHttpRequest();
_req.onreadystatechange = this._sc;
_req.open("GET", url, true);
_req.send();
} ;
}


UPDATE: the above has a scoping error in it and _req ends up in the global scope. Ooops (or rather, not OOPS). I am fixing it this evening along with a periodical updater object, which is also bigged down witha weird scoping issue.

Usage is simple: you pass the TinyAjax constructor a function that will handle the response then call the desired URL with TinyAjax.ajaxRequest() method. The class will then do all the work for you.

I haven't yet got hold of a Windows Mobile device to test on, so this currently only works with standards favouring browsers like Opera and S60. When I get one I'll add whichever object Windows thinks it wants.

It's now in a file called minim.js and can be got from here: http://slackr.eu/m/src/minim.js.txt

2 comments:

Unknown said...

hi J L!

this looks similar to what frost outputs ;) - but won't work in IE mobile (it uses an ActiveX, not a native XMLHttpRequest object). under 2k sounds like a nice goal too.

get in touch if you want to play around with a prelim release of frost (through pavingways website)! would be happy to get some feedback from your side.

caio, rocco

Unknown said...

hey rocco, I certainly will. I simply haven't put the microsoft cal in yet because I don't have an MS browser to test. I guess it's the ActiveX msxml2 control, but that's just a guess. my immediate needs for for webkit and opera. I'll pop on over and take a look.