Skip to main content

Bug Tracker

Side navigation

#6916 closed bug (invalid)

Opened August 18, 2010 09:51PM UTC

Closed October 12, 2010 04:49AM UTC

Last modified March 13, 2012 10:03PM UTC

xml parse error when using $ajax to load a file: url on IE

Reported by: karger Owned by:
Priority: undecided Milestone: 1.4.3
Component: ajax Version: 1.4.2
Keywords: ie xml parse error Cc:
Blocked by: Blocking:
Description

I've asked about this before but have more facts and a more detailed example. I've got a script that uses $.ajax to fetch an xml file (and specifies dataType "xml"). Under firefox it works perfectly, whether the html and xml files are remote (http url) or local (file: url). Under IE, if the files are remote, everything is fine. But if the files are local, then although the fetch is successful, jquery's internal httpData method fails to parse the xml, and instead invokes the $ajax call's error method and returns a "parseerror" message.

You can find a sample demonstrating the error at http://people.csail.mit.edu/karger/Jquery/XML/test.html that loads a test file at http://people.csail.mit.edu/karger/Jquery/XML/test.xml . It works fine if you access it there, on FF or IE, but if you download the two files and try to load from your local copy, FF works but IE fails with a parseerror. If you change the dataType argument to html, IE will work locally---this shows that the ajax call is successfully fetching the file on IE, but is failing to parse it properly.

So apparently the inconsistency is somewhere inside jquery's httpData parser method, which is territory I'm not equipped to explore. If anyone can help me out, I'd appreciate it.

My backup plan is to change the returned datatype to html, but since the file being loaded is xml this seems like a cop-out (and one that will have trouble with namespaces and will worsen performance when I try to run selectors over the result, right?)

-David

Attachments (2)
  • test.html (1.0 KB) - added by karger August 18, 2010 09:52PM UTC.

    html file that exhibits the error when loading accompanying xml

  • test.xml (0.3 KB) - added by karger August 18, 2010 09:53PM UTC.

    xml file that exhibits the error when loaded by the accompanying html file

Change History (3)

Changed August 19, 2010 12:37AM UTC by dmethvin comment:1

component: unfiledajax
jquery's internal httpData method fails to parse the xml

jQuery never parses the XML itself. If the XMLHttpRequest object returns an XML document, the .responseXML property will return a document tree of the parsed XML.

This page explains the behavior:

http://docs.jquery.com/Specifying_the_Data_Type_for_AJAX_Requests

When loading XML files locally, e.g. from a local drive or CD-ROM, the data received by Internet Explorer is plain text and not text/xml. In this case, use the dataType parameter to load the xml file as text, and parse the returned data within the success function.

That's an old documentation example and needs to be moved to http://api.jquery.com/jQuery.ajax/ .

Changed August 19, 2010 05:11PM UTC by karger comment:2

This is very helpful information. I am curious: given that one goal of jquery is to provide a platform-independent interface to working with dom/xml, wouldn't it be appropriate for jquery to hide the IE idiosyncracy mentioned above by performing internally the check specified in the provided documentation---ie, to place _inside_ jquery the rule that an ajax call with datatype xml should, in IE, parse the returned document as xml _before_ calling the success function so that IE looks the same as other browsers?

Changed October 12, 2010 04:49AM UTC by addyosmani comment:3

keywords: → ie xml parse error
priority: → undecided
resolution: → invalid
status: newclosed

karger: That certainly is something which we could consider. If you would like to submit it as an enhancement request, please feel free to.