icc97
icc97

Reputation: 12863

Firefox jquery ajax JSONP call not working

I'm trying to get a JSONP $.ajax request working. It works fine in Chrome and IE but it is failing in 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.

This is a basic demo site (http://andysylvester.com/files/reader/) will work with Chrome and IE but not Firefox.

The nytRiver.js JSON call actually returns a javascript function call to onGetRiverStream see the documentation here: http://riverjs.org/#structureOfRiverjs

<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>

Upvotes: 0

Views: 1573

Answers (2)

icc97
icc97

Reputation: 12863

The problem was a Firefox add-on Privacy Badger. It was blocking rss.scripting.com as a 3rd party tracker.

I have the same add-on installed for Google Chrome - although in the beginning it was not blocking rss.scripting.com. However once it did block it then Chrome debugging tools manage to better Firebug and it gives the following error:

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

That implies that its an ad-blocking add-on causing the problem.

Upvotes: 0

guest271314
guest271314

Reputation: 1

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/

See jQuery.getScript()

Upvotes: 1

Related Questions