Site Moved

This site has been moved to a new location - Bin-Blog. All new post will appear at the new location.

Bin-Blog

Smallest Ajax Library - jx

I am trying to create the smallest Ajax library - I call it jx. Like many other javascript developers, I hate libraries. The primary reason for this is that they are big. When ever I get I library with a functionality I need, I try to extract just the needed function for my program.

So now I am trying to create a library with just one(or two) functions so that who ever is using it will find it easy to extract just the needed functions. But my final goal is to strip away every function that is not crucial - so that the library users won't have to do it.

I have one problem however. I was hoping that I could make it simple enough to do this...
var data = jx_callScript('script.php?arg=value');

But as of yet, I am finding it impossible to do. I need at least two functions - like this.

function callBack(data) {
 /*
 ...
 */
}
jx_callScript('script.php?arg=value',callBack);

This is because of jx_http.onreadystatechange = functionName; where 'onreadystatechange' must have a function attached to it. When the browser finishes fetching the data from the server, it will call the given function. But I want to get it as a return value.

If someone knows how to get over this obstacle(or even if it possible), please let me know.

3 Comments:

Anonymous said...

You could always do it as an anonymous function. Like this:

jx_http.onreadystatechange = function() {
// do stuff
}

Anonymous said...

Checkout my demo - not sure if it helps though! :)

http://rockstars.homedns.org/smallestajax/index.php

And the code here:

http://rockstars.homedns.org//smallestajax/view-index.php

Anonymous said...

I think the only way to do that is to use the Synchronous mode.