简体   繁体   English

Firefox jquery ajax JSONP调用不起作用

[英]Firefox jquery ajax JSONP call not working

I'm trying to get a JSONP $.ajax request working. 我正在尝试使JSONP $.ajax请求工作。 It works fine in Chrome and IE but it is failing in Firefox v30. 它在Chrome和IE中正常运行,但在Firefox v30中失败。

When it fails it doesn't given any error - at least Firebug doesn't show any errors, it just never calls the callback function. 当它失败时,它不会给出任何错误-至少Firebug不显示任何错误,它永远不会调用回调函数。

This is a basic demo site ( http://andysylvester.com/files/reader/ ) will work with Chrome and IE but not Firefox. 这是一个基本的演示站点( http://andysylvester.com/files/reader/ ),可与Chrome和IE一起使用,但不能与Firefox一起使用。

The nytRiver.js JSON call actually returns a javascript function call to onGetRiverStream see the documentation here: http://riverjs.org/#structureOfRiverjs nytRiver.js JSON调用实际上返回了对onGetRiverStream的javascript函数调用,请参见此处的文档: http : onGetRiverStream

<html>
    <head>
        <title>Minimal River.js Feed Reader</title>
        <script src="http://fargo.io/code/jquery-1.9.1.min.js"></script>
        <script>
            var theRiver;
            function onGetRiverStream (updatedFeeds) {
                theRiver = updatedFeeds;
        displayFeeds();
                }
            $.ajax ({ 
                url: "http://rss.scripting.com/rivers/nytRiver.js",  
                dataType: "jsonp"
                });
      function displayFeeds() {
        var feedText = "";
        // Create title
        for (var i in theRiver.updatedFeeds.updatedFeed) {
           feedText = feedText + theRiver.updatedFeeds.updatedFeed[i].feedTitle + " <a href=" + theRiver.updatedFeeds.updatedFeed[i].feedUrl + "> (Feed) " + "</a><br>"; 
           feedText = feedText + "<a href=" + theRiver.updatedFeeds.updatedFeed[i].item[0].link + ">" + theRiver.updatedFeeds.updatedFeed[i].item[0].title + "</a><br>"; 
           feedText = feedText + theRiver.updatedFeeds.updatedFeed[i].item[0].body + "<br>"; 
           feedText = feedText + "<br>";
        }
          document.getElementById("demo").innerHTML = feedText; 
      }
            </script>
    </head>
<body>
    <h1><center>Minimal River.js Feed Reader</center></h1>
    <p id="demo">Wating for feeds to load....</p> 
</body>
</html>

Try 尝试

$(function() {

    onGetRiverStream = function (updatedFeeds) {
                theRiver = updatedFeeds;
                displayFeeds();
                };

    displayFeeds = function() {
        var feedText = "";
        // Create title
        for (var i in theRiver.updatedFeeds.updatedFeed) {
           feedText = feedText + theRiver.updatedFeeds.updatedFeed[i].feedTitle + " <a href=" + theRiver.updatedFeeds.updatedFeed[i].feedUrl + "> (Feed) " + "</a><br>"; 
           feedText = feedText + "<a href=" + theRiver.updatedFeeds.updatedFeed[i].item[0].link + ">" + theRiver.updatedFeeds.updatedFeed[i].item[0].title + "</a><br>"; 
           feedText = feedText + theRiver.updatedFeeds.updatedFeed[i].item[0].body + "<br>"; 
           feedText = feedText + "<br>";
        }
          document.getElementById("demo").innerHTML = feedText; 
      };

  $.getScript("http://rss.scripting.com/rivers/nytRiver.js");

});

jsfiddle http://jsfiddle.net/guest271314/T7cZL/ jsfiddle http://jsfiddle.net/guest271314/T7cZL/

See jQuery.getScript() 参见jQuery.getScript()

The problem was a Firefox add-on Privacy Badger . 问题出在Firefox附加组件Privacy Badger上 It was blocking rss.scripting.com as a 3rd party tracker. 它阻止rss.scripting.com作为第三方跟踪器。

I have the same add-on installed for Google Chrome - although in the beginning it was not blocking rss.scripting.com. 我为Google Chrome安装了相同的加载项-尽管一开始它并没有阻止rss.scripting.com。 However once it did block it then Chrome debugging tools manage to better Firebug and it gives the following error: 但是,一旦确实阻止了它,那么Chrome调试工具就可以更好地解决Firebug并产生以下错误:

net::ERR_BLOCKED_BY_CLIENT

A quick SO search brings up this answer: I am getting Failed to load resource: net::ERR_BLOCKED_BY_CLIENT with Google chrome 快速SO搜索得出以下答案: 我无法使用Google chrome加载资源:net :: ERR_BLOCKED_BY_CLIENT

That implies that its an ad-blocking add-on causing the problem. 这意味着它是一个阻止广告的插件,从而导致了问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM