0

I have two files in the same directory, fetch.html & other.xml (so this doesn't appear to be a CORS issue.) - there are no errors in the console and the network tab shows that I have sucessfully retrieved the xml file.

I try selecting an element from other.xml ($("restaurant")) in the console and it returns an empty array without any errors. I've cleared cache and renamed the files but nothing is changing. Does anyone have an idea of why this is happening?

At the bottom of the body in fetch.html I have this script:

<script>
$(function(){
    $.ajax({
        url: "other.xml",
        success: function(data) {
            console.log("Success");
        }
    });
});
</script>

other.xml looks like:

<?xml version="1.0"?>
<restaurants>
    <restaurant name="Pan Africa Market" address="1521 1st Ave, Seattle, WA" lat="47.608940" lng="-122.340141" type="sitdown"/>
    <restaurant name="Buddha Thai &nbsp; Bar" address="2222 2nd Ave, Seattle, WA" lat="47.613590" lng="-122.344391" type="bar"/>
    <restaurant name="The Melting Pot" address="14 Mercer St, Seattle, WA" lat="47.624561" lng="-122.356445" type="sitdown"/>
    <restaurant name="Ipanema Grill" address="1225 1st Ave, Seattle, WA" lat="47.606365" lng="-122.337654" type="sitdown"/>
    <restaurant name="Sake House" address="2230 1st Ave, Seattle, WA" lat="47.612823" lng="-122.345673" type="bar"/>
    <restaurant name="Crab Pot" address="1301 Alaskan Way, Seattle, WA" lat="47.605961" lng="-122.340363" type="sitdown"/>
    <restaurant name="Mama's Mexican Kitchen" address="2234 2nd Ave, Seattle, WA" lat="47.613976" lng="-122.345467" type="bar"/>
    <restaurant name="Wingdome" address="1416 E Olive Way, Seattle, WA" lat="47.617214" lng="-122.326584" type="bar"/>
    <restaurant name="Piroshky Piroshky" address="1908 Pike pl, Seattle, WA" lat="47.610126" lng="-122.342834" type="sitdown"/>
</restaurants>
7
  • 1
    set dataType : 'xml' in the ajax function to have the result parsed as XML Commented Dec 17, 2013 at 16:50
  • @adeneo: It appears to already be parsed as XML .. but adding that didn't log anything in the console :/ Commented Dec 17, 2013 at 16:54
  • Try it like this, and tell us what you get -> jsfiddle.net/bDj5Y Commented Dec 17, 2013 at 16:56
  • @adeneo: Hmm it still doesn't log "Success" - I put the response in comments below your jQuery - jsfiddle.net/bDj5Y/1 Commented Dec 17, 2013 at 16:57
  • That's a parse error, you don't have valid XML, and that causes issues. Commented Dec 17, 2013 at 16:59

1 Answer 1

1
<restaurant name="Buddha Thai &nbsp; <---

&nbsp; is not a predefined entity in XML. You can't use it in a plain XML document. If need &nbsp; in your app then you can escape it as &amp;nbsp;

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.