我想通过jQuery AJAX提取RSS提要,但每次我都这样做,我得到一个parsererror.我的Feed比较复杂(使用CDATA和自定义命名空间),因此我尝试删除返回的文档(以及其他一百万种组合),但即使使用非常简单的文档,它仍然会失败.这是我的AJAX代码:
$.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);
}
});
控制台输出:
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>
解决方法
确保使用application-RSS xml或text / xml的Content-Type标头提供文档.