1

http://jsfiddle.net/bpBtC/

我正在使用博客 xml 提要,但它不起作用,有人可以帮助我了解我哪里出错或缺少什么。

$(document).ready(function () {
    $.ajax({
        type: "GET",
        url: "http://www.blogger.com/feeds/2399953/posts/default",
        dataType: "xml",
        success: xmlParser
    });
});

function xmlParser(xml) { 
    $(xml).find("entry").each(function () {
        $(".entirecont").append($(this).find('title').text());
    });
}

​</p>

4

2 回答 2

1

您正在尝试访问您的域之外的域。尝试在您的服务器上创建代理以检索 xml。浏览器不允许在 javascript 中进行跨域访问。

于 2012-04-16T23:38:41.070 回答
0

您需要 jsonp 数据类型才能访问跨域 ajax 调用。请参阅下面的示例并查看http://www.ibm.com/developerworks/library/wa-aj-jsonp1/中的 jsonp 是什么

$(document).ready(function () {
    $.ajax({
        type: "GET",
        url: "http://www.blogger.com/feeds/2399953/posts/default",
        dataType: "xml",
        success: xmlParser,
        dataType: "jsonp" // add this line
    });
});

希望能帮助到你

更新

这是您的 jsfiddle的更新版本

于 2012-04-17T00:03:56.657 回答