IE8跨域Ajax调用问题

时间:2015-05-08 00:00:09

标签: javascript jquery ajax rss

你好,所以我试图找出我的问题,但没有运气,但我已经找到了网站。

所以我试图做的是调用RSS提要的ajax调用

我遇到的一个问题是Feed没有启用COR,所以我使用这个脚本来解决这个问题。

github: https://github.com/padolsey-archive/jquery.fn/blob/master/cross-domain-ajax/jquery.xdomainajax.js

Firefox Chrome和IE9 +中的一切正常

只是IE8没有100%运作

因此调用数据但是锚标记的文本没有显示但是链接正常工作

任何建议都会感激不尽

我尝试了不同的变体:

var $xml = $($.parseXML(data.responseText)); 

的index.html:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

    <title>Untitled Document</title>
    <script src="http://code.jquery.com/jquery-1.11.2.min.js" type="text/javascript"></script>
    <script src='jquery.xdomainajax.js'></script>
</head>

<body>

    <style>
        #feed-results a {
            display: block;
        }
    </style>
    <h1>Feed Contents</h1>
    <div id="feed-results">

    </div>
    <script type="text/javascript" src="feedParser.js"></script>
    <script type="text/javascript">
        $(function() {
            feedParser.getFeedContents('http://aon.mediaroom.com/news-releases?pagetemplate=rss&category=821');
        });
    </script>
</body>

</html>

ajax电话:

var feedParser = (function($) {
    function getFeedContents(url) {
        $.ajax({
            url: $.trim(url),
            type: "GET",
            dataType: "xml",
            success: function(data) {
                console.log(data.responseText);
                var $xml = $(data.responseText);
                $xml.each(function(index, value) {
                    var regex = /<link>(.*?)<\/link>/ig,
                        links = regex.exec(value);
                    $this = $(value),
                        selitem = {
                            title: $this.find("title").text(),
                            link: links[1],
                            description: $this.find("description").text(),
                            pubDate: $this.find("pubDate").text(),
                            guid: $this.find("guid").text()
                        }
                    $('#feed-results').append(' <ul> <a href=" ' + selitem['link'] + ' "> ' + selitem['title'] + ' </a> </ul> ');
                });
            }
        });
    }

    return {
        'getFeedContents': getFeedContents
    }
})(jQuery);

XML文档(拉动Feed /这只是来源) Feed链接: http://aon.mediaroom.com/news-releases?pagetemplate=rss&category=821

<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<rss version="2.0">
    <channel>
        <title>News Releases | Aon (Aon Benfield)</title>
        <link>http://aon.mediaroom.com/</link>
        <description>Aon plc Global Media Relations</description>
        <item>
            <title>ILS records continue to tumble as innovation heralds $1.7bn first quarter issuance, according to Aon Benfield study</title>
            <link>http://aon.mediaroom.com/index.php?s=25776&amp;item=137214</link>
            <description></description>
            <pubDate>Wed, 15 Apr 2015 12:01:00 -0400</pubDate>
            <guid>http://aon.mediaroom.com/index.php?s=25776&amp;item=137214</guid>
        </item>
        <item>
            <title>March windstorms cause billion-dollar damage across Europe, according to Aon catastrophe study</title>
            <link>http://aon.mediaroom.com/2015-04-08-March-windstorms-cause-billion-dollar-damage-across-Europe-according-to-Aon-catastrophe-study</link>
            <description>Windstorm Niklas recorded as costliest non-U.S. event in first quarter 2015</description>
            <pubDate>Wed, 08 Apr 2015 11:46:00 -0400</pubDate>
            <guid>http://aon.mediaroom.com/2015-04-08-March-windstorms-cause-billion-dollar-damage-across-Europe-according-to-Aon-catastrophe-study</guid>
        </item>
        <item>
            <title>Global reinsurer capital continues to build to USD575 billion, according to the latest Aon Benfield Aggregate study</title>
            <link>http://aon.mediaroom.com/index.php?s=25776&amp;item=137202</link>
            <description>Alternative capital increases 28% to USD64 billion</description>
            <pubDate>Mon, 30 Mar 2015 12:28:00 -0400</pubDate>
            <guid>http://aon.mediaroom.com/index.php?s=25776&amp;item=137202</guid>
        </item>
        <item>
            <title>Aon comments on Budget 2015 </title>
            <link>http://aon.mediaroom.com/index.php?s=25776&amp;item=137196</link>
            <description></description>
            <pubDate>Wed, 18 Mar 2015 12:46:00 -0400</pubDate>
            <guid>http://aon.mediaroom.com/index.php?s=25776&amp;item=137196</guid>
        </item>
        <item>
            <title>Evolving solvency regimes create further opportunities for Asia insurers</title>
            <link>http://aon.mediaroom.com/index.php?s=25776&amp;item=137188</link>
            <description></description>
            <pubDate>Thu, 12 Mar 2015 05:22:00 -0400</pubDate>
            <guid>http://aon.mediaroom.com/index.php?s=25776&amp;item=137188</guid>
        </item>
    </channel>
</rss>

0 个答案:

没有答案