weixin_33717117 2017-06-22 10:25 采纳率: 0%
浏览 17

返回null的ajax调用

I have this small script (fiddle) in charged for reading some blog XML. The problem is that it simply stopped working a few days ago. It seems the Ajax function is always returning null, even though there is data in the specified URL.

<script>
var toType = function(obj) {
    return ({}).toString.call(obj).match(/\s([a-zA-Z]+)/)[1].toLowerCase()
}

var buildRSS = function (container_id){
    $.ajax({
        type: "GET",
        url: "http://bloginstructions.blogspot.dk/rss.xml",
        dataType: "xml",
        success: function(result){
            var values = getEntries(result)
            console.log(result)
            for (var i = 0; i < 10; i++) {
                var entry = values[i],
                    info = entry.__text.split("
"),
                    title = info[0],
                    link = info[1],
                    date = entry.pubdate.match(/(.*) \d/)[1],
                    snippet = entry.description.replace(/<\/?[^>]+(>|$)/g, "").substring(0,350)+'...';

                var html = '<a href="' + link + '"><div><h4>' + title + '</h4><p>' + date + '</p><p>' + snippet + '</p></div></a>'
                $('#' + container_id).append(html)

            }
        }
    })
}

function getEntries(rawXML){
    var x2js = new X2JS();
    console.log(rawXML);
    var xml = rawXML.responseText;
    match = xml.match(/<item>(.*)<\/item>/);
    xml = match[0] || '';
    var json = x2js.xml_str2json(xml);
    json = json.rss.channel.item;
    return json
}
</script>

<div id="rssfeed">

</div>
<div id="rss">

</div>

<script>
$(document).ready(function() {
    buildRSS('rssfeed')
    });
</script>
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 matlab不知道怎么改,求解答!!
    • ¥15 永磁直线电机的电流环pi调不出来
    • ¥15 用stata实现聚类的代码
    • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
    • ¥20 docker里部署springboot项目,访问不到扬声器
    • ¥15 netty整合springboot之后自动重连失效
    • ¥15 悬赏!微信开发者工具报错,求帮改
    • ¥20 wireshark抓不到vlan
    • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
    • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持