views:

51

answers:

1

Hello,

I'd like to do something like this:

var res = myAjax.post();

myAjax is basically my own ajax wrapper (asynchroneous). I don't necessary need the chaining, but i'd like to be able to do the call like shown above. I'd like a callback to be handled by the object itself. I've read about asynchroneous method queues, but, honestly, couldn't fully understand it. I know i could use a synchroneous ajax call, but it should be possible to do it asynchroneously as well if i understand it correctly. Any help is very appreciated. Thank you.

A: 

I've done a demo here that might be something along the lines of what you mean...

In that demo, there are two types of objects: MyAjax which has the 'post' method as above, and a MyRes object with a getData method that will return null until the async call has successfully completed. After it has completed, it will return the data fetched from the ajax call.

In the demo, I have a function checking for the response every second, but the post method also handles a callback which allows you to be notified when the ajax call has completed successfully.

I don't know why you'd want to do it this way, but it is doable.

sje397
Thank you for the demo. There are probably a few ways of doing this, but i guess it's still not the same. To answer your question, i simply want to reduce the ammount of the code needed to write an ajax call - that's all. Lots of callbacks simply clutter the code so i thought i could clean it up a bit.
Marius