Please Donate: The Leukemia & Lymphoma Society - Scenic Shore 150 Bike Tour [Donate Here]

Ajax Issue with Safari

March 21st, 2005

A couple of months back I was experimenting with the XHR object in Safari and attempted to pull an XML document from the server. It worked perfectly in Firefox, but it bombed out on Safari for no apparent reason. After several hours of trying to debug it I discovered that Safari chokes on the "title" element in the XML documents.

My best guess is that in XHTML the "title" element can only be shown once, so it is not possible to use document.getElementsByTagName("title") in Safari and get a collection back. It seems to return a null reference. And that is very disappointing. Come on Apple!

Yesterday I tried to pull an actual RSS 2.0 document from the server which has many "item" elements which encloses a blog entry, including the "title" element. As I try my RSS Include example I find it fails when it tries to read that element.

Safari Bug Title

Previously I was able to solve the problem by simply renaming the elements. In this case I am reading a standard XML format and should be able to read it as is, but I may need to find another way to iterate over those elements. My initial tests to solve this bug are on this page are to simply get all child nodes to the "item" node and check the tagName value of each element. As I try that I find that both Safari and Firefox require a lot more processing power to work though the DOM that way. It will require more work to speed it up to a reasonable speed.

Of course the best solution is to have Apple fix the bug in Safari 1.3. You can let them know about it by viewing the RSS Include page and then use the Safari menu in the top left to report a bug. Once enough people submit the bug I am sure they will take notice.

[ Web Development Tools for the Power Developer ]

5 Responses to “Ajax Issue with Safari”

  1. Christopher Gervais Says:

    Is this fixed with Safari 1.3 (v312) included with the Mac OS X 10.3.9 update?

  2. Brennan Stehling Says:

    I was actually working on testing that last night.

    That specific bug is fixed and that is great, but there now seems to be a new bug. I find that when I load a page which will generate more than one XHR request it will fail after the first one. But if I reload the page it can do as many requests as I like. With the RSS Include example you can load the page just fine but pressing the Load Headlines but will cause an error because the Request Status is undefined. I do not know why. Perhaps the content is cached and it simply knows that. Apple may be adding a feature which I need to learn about.

    I will post a new blog entry once I have the details worked out.

  3. Jeremy Keith Says:

    I've been having a hell of a time with this same problem here:

    http://elsewhere.adactio.com/

    It is indeed a caching issue.

    The only way to get around seems to be to *not* test for a status of 200.

    In effect, Safari is punishing you for being rigourous about status testing. If you assume that everything is okay, then Safari serves up the cached version.

    I guess you could still test for a status value of 200 or 'undefined'.

    Still... what a pain. I understand why caching is a good idea but it would be good to cache everything including the response status.

  4. Brian Says:

    I have the same problem. I hacked around it by ensuring that my request was always unique. I just added the current time in milliseconds onto the end of my request, and it worked perfectly.

  5. Joe Says:

    now it's ok with RSS but still bug with Atom.