Site Moved

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


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) {

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.


Daniel E. Renfer said...

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

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

techRock said...

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

And the code here:

Anonymous said...

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