Ticket #7779 (closed bug: invalid)
$(xml).children() behaves differently depending if it's loaded locally or on a web server
|Reported by:||eslachance@…||Owned by:|
This being my first bug report, please be gentle if it is either missing information or due to something on my end.
I was build a menu with UL and LI elements by recursively traversing an XML file generated externally. This worked fine locally, it displayed all the menu items and then applied superfish to it for displaying.
When I uploaded it to my webhost however (and even with local XAMPP install), it stopped working correctly. After some help from the jQuery forums and a lot of headaches, the following "bug" game to light:
When loading an XML file through an ajax call (either .ajax or .get) and retrieving the number of children of the root element through $(xml).children().length , the "root" is different depending on whether the file is opened on the hard drive or through a URL. Through a URL it seems to see the "document" (xml file/top/whatever), while locally it sees the actual root element in the XML.
It's not possible to reproduce this on jsfiddle simply because I'm externally loading the xml file (it seems to work fine when defining XML as a string variable with the contents being the xml itself). So I placed this on the web and separated it from my website design. URL is here: http://www.chromocode.ca/jqueryxmlrootbug/
To see the different locally, save the html and XML file on your drive in the same folder, and double-click on the html file. The "undefined" element should be gone. (note: for some odd reason RockMelt, based on chrome, couldn't load the menu locally whatever I did, not sure why)
Current workaround: Calling $(xml).children().children() for the first element, which works on the website but not when loading locally.