Archive for the 'AJAX' Category

RFacebook to see some updates and code slimming

Friday, January 4th, 2008

It has been a while since I’ve updated RFacebook, and I finally have the time to do so. Again, I’m always looking for dedicated help, since my time is limited as it is. The project has gotten quite involved, and recent API changes + the Rails 2.0 release has complicated it somewhat.

In spite of the backlog of bugs and feature requests, you should see some improvements over the next few weeks. I plan on slimming down the code as much as possible, as well as removing some poorly designed portions of the library. I’ll have a few interim updates (0.98 and 0.99), but RFacebook 1.0 will have a much more solid core, with the Rails extensions pulled exclusively into a plugin.

Please let me know your biggest complaints with RFacebook (features, bugs, and code design) so that I can address them all fully. Good luck Facebooking!

Making AJAX calls onUnload

Friday, July 14th, 2006

I suppose this will be my first “official” developer blog entry, so bear with me if it seems a little sparse. This summer I’ve been doing a ton of work with object oriented Javascript and AJAX, and up until today the AJAX part has been mostly simplified by Atlas webservice proxies. However, today I hit one of those problems that just hasn’t been very well documented by anybody else, so I thought I’d write something about it.

Basically, our application keeps a form of session state server-side, and it needs to be notified when the browser window is closed or refreshed. Clearly, the thing to do here is to hook into the window.onUnload event (side note for new Atlas developers: don’t use window.onUnload, use Sys.Application.unload.add([yourUnloadHandler]) instead).

So at first I just went happily along, sending the usual XmlHttpRequest when the page unloaded. However, this of course poses a problem with the asynchronous response from the server: by the time the response comes back, the page has unloaded and the callback function won’t exist anymore. This generates an ugly Javacript “function is not defined” error. In any case, here’s a nice little picture of what happens:

AsynchronousJavacriptUnload

The solution here is to make sure that any AJAX requests that you make onUnload are make synchronously instead of asynchronously (SJAX?). This will ensure that the page doesn’t finish unloading before the server response comes back. Hence, the much happier picture below:

SynchronousJavascriptUnload

Bertrand Le Roy has a quick chunk of Javascript that you can use to do alter the XmlHttpRequest object to temporarily do only synchronous calls. Use this Javascript before any AJAX calls in your unload event, and you’ve solved your problem!