Forum Discussion

Claudius's avatar
12 years ago

Include RSS feed information from another site into custom component

I'd like to show an RSS feed (or alternatively even JSON) from another domain within a Lithium Custom component, but keep running into severla issues which I blame cross site scripting prevention a.k.a. "same origin policy" for.

 

Anyone got a working solution for that use case?

 

 

Here's what's not working for me right now using a wrapper to create a JSONP out of the original XML feed at http://share.skype.com/stats_rss.xml :

<@liaAddScript>
var jqxhr = LITHIUM.jQuery.ajax({ url: "http://ajax.googleapis.com/ajax/services/feed/load?v=1.0&q=http://share.skype.com/stats_rss.xml&output=json_xml&callback=ShowUserCount",
   Type:"GET" ,
   dataType:"jsonp",
   contentType: "application/json" })
    .done(function() { alert("success"); })
    .fail(function(xhr, status, error) { alert("Error: " + error + "(" + status + ") - Details: " + xhr.status + " \nxhr.responseText: " + xhr.responseText); });
</@liaAddScript>

 

  • ChiaraS's avatar
    ChiaraS
    Lithium Alumni (Retired)

    Hi, using JSONP is the way to go I think, if you need to get the data from a different domain.

     

    This code seems to work (I replaced it with your url):

    <@liaAddScript>
    LITHIUM.jQuery.ajax({
    	url: 'http://ajax.googleapis.com/ajax/services/feed/load?v=1.0&q=http://share.skype.com/stats_rss.xml&output=json_xml',
    	dataType: 'jsonp',
    	jsonp: 'callback',
    	jsonpCallback: 'jsonpCallback',
    	success: function(){
    		//alert("success");
    	}
    });
    
    function jsonpCallback(data){
    	var xml = data.responseData.xmlString;
    	alert(xml);
    	var feed = data.responseData.feed;
    	alert(feed);
    }
    </@liaAddScript>

     

    • rholder's avatar
      rholder
      Ace

      I am looking for a similar solution, however I am not a developer.   Is the code above all you need to paste into the component content box, or is there more?