parseerror when getting XML via jQuery AJAX

ajax, jquery, xml

Solution

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

Problem

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> ```

Original source