微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

通过jQuery AJAX获取XML时的parseerror

我想通过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标头提供文档.

原文地址:https://www.jb51.cc/jquery/181377.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐