jFeed - sucess function not being executed (jQuery plugin)

3.6k Views Asked by At

I have the following Javascript code, where feed is a valid url to an rss feed.

jQuery(function() {

        jQuery.getFeed({
            url:feed,
            success: function(feed){
                      alert(feed);
                      }
        });
    });}

when i run this the alert never shows up. using firebug i can see the connection being made and the response from the feed.

Note: i know this is a security issue and some browsers block it, this isnt the case at hand because i have worked around that issue and the browser no longer blocks the connection

EDIT : for some reason i cant make the comment show up so here:

The call isnt being proxyed by a script at the moment, since this is a test im just overriding browser security settings with:

netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead");
4

There are 4 best solutions below

4
On BEST ANSWER

With the information you give, we can see that your call is correct. The problem is probably somewhere else. In suggest that you dig in jFeed source code and disable feed parsing in $.ajax success method:

    $.ajax({
        type: 'GET',
        url: options.url,
        data: options.data,
        dataType: 'xml',
        success: function(xml) {
            var feed = xml; // <== was "var feed = new JFeed(xml);"
            if(jQuery.isFunction(options.success)) options.success(feed);
        }
    });

If your alert pops up, it's a feed parsing problem. In this case, you can check that the xml is correct and submit it here for further investigation.


I've run some tests and checked jQuery code. You said that you worked around the browser security problem: I guess that you installed on you server a proxy script that will download the rss file from the distant server and then transmit it to your ajax request (because the browser will block ajax calls to a server different from the one your page is on). When making an ajax call with dataType : 'xml', jQuery expects that the content type of the response to contain the string "xml":

var ct = xhr.getResponseHeader("content-type"),
  xml = type == "xml" || !type && ct && ct.indexOf("xml") >= 0,
  data = xml ? xhr.responseXML : xhr.responseText;

Here are my questions:

  • Did you use a script as proxy script as I suppose ?
  • Does this script set the content-type to something containing xml ?

Here is a minimalistic php sample shipped with jFeed:

<?php
header('Content-type: application/xml');
$handle = fopen($_REQUEST['url'], "r");

if ($handle) {
    while (!feof($handle)) {
        $buffer = fgets($handle, 4096);
        echo $buffer;
    }
    fclose($handle);
}
?>
0
On

one more thing if you want to read content from custom namespaces:

the above ('escaped colon') method won't work properly in Chrome but this ('nodeName') approach will work in all browsers:

item.mediaThumbnail = $($(this).find("[nodeName=media:thumbnail]").eq(0)).attr("url");

1
On

I had a similar problem. Try hard coding the URL into the url: and see if that works rather than setting a feed variable.

You have an extra } at the end of your segment, is that just an extra part of your code?

0
On

Just to add that for those needing to get content out of feeds with customized namespaces, with jFeed, you could do stuff like so

<dc:creator>SomeBody Name</dc:creator>
<media:thumbnail url="someimage.jpg" />

Add your own items to JFeed Prototype

JFeedItem.prototype = {
        title: '',
        link: '',
        description: '',
        updated: '',
        id: '',
        mcontent:'',
        mdescr:'',
        mcredit: '',
        dcreator:'',
        mthumbnail:''
    };

Then to the prototype of JRss and JAtom, which ever your using, add the following the item loop

item.dcreator = $(this).find("dc\\:creator").eq(0).text();
item.mcontent = $(this).find("media\\:content").eq(0);
item.mdescr = $(this).find("media\\:description").eq(0).text();
item.mcredit = $(this).find("media\\:creator").eq(0).text();
item.mthumbnail = $( $(this).find("media\\:thumbnail").eq(0) ).attr("url");

Hope this one day helps someone too struggling with handling namespaces in xml with jQuery. I am working with RSSfeeds from the NYT and needed to get media thumbnails to display in links to video content, and had to spend some time to figure out how to go work thru namespaces