Bug Tracker

Ticket #6916 (closed bug: invalid)

Opened 4 years ago

Last modified 2 years ago

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:
Blocking: Blocked by:

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

test.html Download (1006 bytes) - added by karger 4 years ago.
html file that exhibits the error when loading accompanying xml
test.xml Download (331 bytes) - added by karger 4 years ago.
xml file that exhibits the error when loaded by the accompanying html file

Change History

Changed 4 years ago by karger

html file that exhibits the error when loading accompanying xml

Changed 4 years ago by karger

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

comment:1 Changed 4 years ago by dmethvin

  • Component changed from unfiled to ajax

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/ .

comment:2 Changed 4 years ago by karger

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?

comment:3 Changed 4 years ago by addyosmani

  • Keywords ie xml parse error added
  • Priority set to undecided
  • Status changed from new to closed
  • Resolution set to invalid

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

Note: See TracTickets for help on using tickets.