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条回答 默认 最新

    报告相同问题?