(More) Ajax Woes in Safari

The more I deal with Ajax and Safari, the more interesting problems I get with the combo from time to time. Since my last run in with the dual, which forced me to rebuild that particular section of the site using more traditional means, I have recently discovered one more issue having to do with multiple

1
XMLHttpRequest

calls via the same object from the same page. The short version of the story is: It CAN’T be done in Safari* (or not in the method that I know of). Firefox and IE, however, seem perfectly happy with using a single object to make multiple asynchronous calls.

Fortunately I am not crazy. I found an article that briefly touches on this issue. This article is also a very good short tutorial on how to get started on Ajax (though the author uses a Ruby backend to iterate the codes, which can easily be replaced using any code you are comfortable with.). Another article offers more depth on the same issue with some code samples to show (via Ajaxian.com).

To get around the problem, one way is to simply create multiple objects, one for each call request, as opposed to have one object to handle all the requests. If you don’t do this, when you make one

1
XMLHttpRequest

call, all the other Ajax fields on the same page will start loading as if they are expecting something back from the same request (for which they’ll wait an eternity and never get anything back).

Sometimes I just don’t know how I solve these kinds of voodoo-like problems. Even Google is powerless before I knew what the problem was. I mean, how do you Google for problems you don’t even know how to describe? And this issue was particularly annoying because Safari’s Javascript console didn’t report any errors.

*I also discovered that the same issue takes place in Webkit (the HTML rendering engine at the heat of Safari) based browsers, including Shiira. Though strangely enough, Camino (a cousin of Mozilla FireFox), much of whose gut is based on Safari’s renderer, didn’t have the problem at all! It’s also interesting to note that Opera 9 also suffers from the same issue.