Parseerror when getting XML through jQuery AJAX

I want to pull the RSS feed through jQuery AJAX, but every time I do this, I get a parsererror. My channel is relatively complex (using CDATA and custom namespaces), so I tried to hide the returned document (along with millions of other combinations), but even with a very simple document it still doesn't work. 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>
+3
source share
1 answer

Make sure you are using a document with the title Content-Type application/rss+xmlor text/xml.

+4
source

Source: https://habr.com/ru/post/1727448/


All Articles