Search code examples
jqueryjquery-pluginsjfeed

jFeed - sucess function not being executed (jQuery plugin)


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");

Solution

  • 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);
    }
    ?>