3

I want to pull an RSS feed via jQuery AJAX, but every time I do, I get a parsererror. My feed is relatively complex (using CDATA and custom namespaces), so I tried stripping down the document returned (along with a million other combinations), but even with an extremely simple document, it still fails. This is my AJAX code:

$.ajax({
    type: 'GET',
    url: ...,
    dataType: 'xml',

    success: function(xml) {
        ...
    },

    error: function(xhr, textStatus, error) {
        console.log('status: ' + textStatus);
        console.log(xhr.responseText);
        showError('an unknown error occurred while trying to fetch the feed: ' + xhr.status);
    }
});

Console output:

status: parsererror
<?xml version="1.0"?>

<rss version="2.0">
    <channel>
        <title>title</title>
        <link>link</link>
        <description>desc</description>

        <lastBuildDate>build date</lastBuildDate>
        <generator>gen</generator>
    </channel>
</rss>
5
  • 3
    What's the Content-Type header. Commented Jan 6, 2010 at 5:18
  • You didn't show the url but is it possible that you're trying to make a cross domain request (which is impossible) and that's why it's failing? Commented Jan 6, 2010 at 5:19
  • What is the original xml file look like and what does error varable contain. Commented Jan 6, 2010 at 5:20
  • 1
    Yep, my server didn't automatically set the Content-Type header. Thanks! Commented Jan 6, 2010 at 5:27
  • @Chandra you should put you comment in the form of an answer so it can be accepted for future readers (and points :) Commented Jan 6, 2010 at 5:42

1 Answer 1

4

Make sure to serve the document with a Content-Type header of application/rss+xml or text/xml.

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.