Skip to main content

Bug Tracker

Side navigation

#4958 closed bug (fixed)

Opened July 23, 2009 03:52PM UTC

Closed January 09, 2011 04:01PM UTC

Last modified July 06, 2012 10:55AM UTC

ajax methods fail in IE for content types ending in +xml

Reported by: jaffathecake Owned by:
Priority: low Milestone: 1.5
Component: ajax Version: 1.3.2
Keywords: xml,rss,ajaxrewrite Cc:
Blocked by: Blocking:
Description

IE doesn't understand content types like application/rss+xml, responseXML contains an empty xml document.

To recreate, try and load an RSS file using jquery.get in IE 6 / 7. Ensure the RSS file is served as application/rss+xml.

As a workaround, you can create a new ActiveXObject("Microsoft.XMLDOM") and feed it the responseText.

Attachments (1)
  • ajaxxmlfix.patch (0.7 KB) - added by jaffathecake July 23, 2009 03:53PM UTC.

    Rough solution

Change History (13)

Changed July 23, 2009 03:56PM UTC by jaffathecake comment:1

The patch above uses browser detection, not sure how you'd solve this via feature detection. Also, the bug doesn't occur in IE8, but giving it the fix does no harm.

Changed November 18, 2009 02:36AM UTC by dmethvin comment:2

Closed dup #4975.

Changed February 03, 2010 04:58PM UTC by zevspitz comment:3

You don't need to create a new XMLDOM object; you can use the existing one.Also, As far as the browser-detection goes, why not just detect data.documentElement === null?

if ( xml ) {
    if (data.documentElement === null && data.parseError.errorCode === 0) {
        data.loadXML(xhr.responseText);
    }
    if ( data.documentElement.nodeName === 'parsererror' ) {
        jQuery.error('parsererror');
    }
}

There is an additional check, for the parseError.errorcode:

If the responseText could not be parsed as XML the first time, there is no point in trying it agasin.

Changed February 03, 2010 05:07PM UTC by zevspitz comment:4

This would also be relevant to #2949

Changed February 03, 2010 05:08PM UTC by zevspitz comment:5

An additional note: for browsers which don't support parseError, an error will be trapped by the calling function

Changed October 26, 2010 06:11PM UTC by addyosmani comment:6

#2109 is a duplicate of this ticket.

Changed October 27, 2010 04:45PM UTC by SlexAxton comment:7

milestone: 1.41.5
priority: majorlow
status: newopen

Changed December 27, 2010 10:37PM UTC by rwaldron comment:8

keywords: xml rssxml,rss,ajaxrewrite

Changed January 09, 2011 04:01PM UTC by jaubourg comment:9

resolution: → fixed
status: openclosed

The new ajax implementation will do the parsing automatically.

Changed July 06, 2012 09:15AM UTC by SeanH comment:10

This is not fixed correctly and it needs additional checks apart from documentElement to distinguish a HTML Dom object from an XML Dom object.

There is a bug in IE 10 (10.0.8400.0), the version included in the windows 8 preview release, that shows that the check was not adequate. In this release no correctly set xml mime type is parsed as xml, instead it is parsed as html. This results in all code relying on jQuery.ajax calls using the dataType xml and content type "text/xml” failing.

My suggestion is the following:

Modify the check for xml to (+-line7889)

if ( xml && xml.documentElement && !xml.forms/* #4958 */ ) {

HTML Dom will have .forms XML Dom will not.

Add an extra converter in jQuery.ajaxSetup for text -> xml. (+-line7771)

"text xml": function (text){
	var xml = jQuery.parseXML(text);
	return xml;
}

Changed July 06, 2012 09:23AM UTC by jaubourg comment:11

@SeanH,

Have you tried to report the bug to the IE team? It's obviously a problem on their end and I'd like to see if we could have this fixed in IE10 before hacking in jQuery.

Also, I don't really see why you redefine the converter while it's already set to parseXML: https://github.com/jquery/jquery/blob/master/src/ajax.js#L358

Changed July 06, 2012 10:23AM UTC by SeanH comment:12

I am going to report the bug to the IE team as well, but since I have investigated this I decided to post here first. I still believe an extra check is required on that line of code regardless if the IE team fixes / doesn't fix the issue.

As to your second question I redefined it simply because I didn't see that code and our code was wasn't working still.

I have found out why it wasn't working. We redefined the parseXML function and the code uses your internal one instead of ours.

We have horrible browser detection code that ensures the xml object returned as the selectSingle node method. We had to extend this for IE 10. Our code heavily relies on this method and we have not written a replacement yet for when IE uses the DOMParser.

(function($) {
	
	$.parseXML = function( data ) 
	{
		
		var xml, tmp;
		try 
		{
			if (!($.browser.msie && ($.browser.version == 9 || $.browser.version == 10)) && window.DOMParser ) 
			{ // Standard
				tmp = new DOMParser();
				xml = tmp.parseFromString( data , "text/xml" );
			} 
			else 
			{ // IE
				xml = new ActiveXObject( "Microsoft.XMLDOM" );
				xml.async = "false";
				xml.preserveWhiteSpace = true;
				xml.loadXML( data );
			}
		} 
		catch( e ) 
		{
			xml = undefined;
		}
		if ( !xml || !xml.documentElement || xml.getElementsByTagName( "parsererror" ).length ) 
		{
			try
			{
				if (data.toString)
					jQuery.error( "Invalid XML: " + data );
			}
			catch (e)
			{
				jQuery.error('Invalid XML (cannot represent object as string).');
			}
		}
		return xml;

	};

})(jQuery);