0

Ok so I have been sitting here staring at my screen for hours and something just isn't working so I had to ask.

I have an XML file that follows this format:

<news attribs="thedate,image,thetext">
    <item thedate="<redacted>" image="<redacted>"><![CDATA[<redacted>]]></item>
    ...
</news>

and here is my JS

$.ajax({
    type: "GET",
    url: "news.xml",
    dataType: "xml",
    success: function (xml) {
        console.log(xml);
        $(xml).find('item').each(function () {
            var date, image, text;
            date  = this.thedate;
            image = this.image;
            text  = this.text();

            console.log(date, image, text);
        });
    },
    error: function () {
        alert("An error occurred while processing the XML file.");
    }

Right now I am literally just trying to get the XML file to load in. I have been working on this for a few hours at work and I have hit a wall and I feel like I'm just missing an obvious error somewhere.The console.log(xml); doesn't post anything to the console which makes me think the file just isn't loading in but it stopped giving me an error so I have NO IDEA.

Side question: I am also not sure about the format for getting the attributes but I need to fix the xml loading before I can even touch that.

2
  • Can you please provide any fiddle with LIVE code? Commented Sep 30, 2015 at 21:40
  • console.log('Result:', xml) would make it pretty clear whether or not it's getting to success or the xml is empty. Commented Sep 30, 2015 at 21:43

1 Answer 1

1

Try something like this :
error: function (xhr,err){ alert(err); }
And when you know what's exactly the error, deal with it.

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

1 Comment

There was an error inside the XML file that I found because of this answer so thank you! There were &'s used throughout and it was throwing errors, ended up replacing them with "&amp;".

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.