You are hereBlogs / Matt's blog / jQuery Ajax Requests on IE6 Need Extra Help To Parse

jQuery Ajax Requests on IE6 Need Extra Help To Parse


By Matt - Posted on 02 July 2009

Using jQuery's .get .post or .ajax features to parse xml results, you may find that only Internet Explorer 6 fails to parse your xml result in the callback function.  You can always count on your friend IE6 to crush productivity!

But before you try this, particularly in newer versions of jQuery, be very sure your XML is well formed and sent with a Content-type: text/xml header.  Either of those situations are more common than we'd like to think.  A firefox extension like Firebug is absolutely critical for figuring out whether or not you have problems from spurious php warnings/notices/etc goofing up IE's xml parsing.  Firefox, correctly in my view, ignores script generated errors.

 

A solution to try if you're stuck with an older jQuery and at your wit's end:

.post("/url",{ "data":vals }, 

     function(xml) { 

            // Force IE6 to parse the XML:
            if (jQuery.browser.msie) { 
                var xmlDoc = new ActiveXObject("Microsoft.XMLDOM"); 
                xmlDoc.loadXML(xml); 
                xml = xmlDoc; 
            }

            // Do whatever you need to do here...

     }

// Be sure to override the default 'xml' in IE and force it as text

,(jQuery.browser.msie) ? "text" : "xml");

 

Hopefully that saves someone else time.

hi,

I was scratching my head for hours and tried lot of combinations to get this work.

This @#$ IE, always sucks time. But thanks to your findings, it actually worked.

Few addons:

I am using IE7, here dataType: "xml" doesnt work, instead, dataType: "XML" works just fine, or else, leave that property unassigned.

 

Yet to test on IE6 & IE8.

 

Thanks again.

Vijay W

Create Live Bookmark

Syndicate content

Recent comments

Latest images