0

I found this site that allows to convert RSS feeds into json. It also provides a way to specify a callback, so i think users are able to make jsonp calls to this web service. However, i tried different ways to do that but none worked. Here is my code:

$(document).ready(function () {
    $.ajax({
        type: "GET",
        url: 'http://www.blastcasta.com/feed-to-json.aspx',
        dataType: "jsonp",
        jsonpCallback: "loadRSS",
        data: {
            feedUrl: 'http://xml.corriereobjects.it/rss/homepage.xml',
            param: "callback"
        },
        success: function (data) {
           var list = "";
           for (var propertyName in data) {
                list+=data[propertyName];
            }
            console.log(list);
        },
        error: function(xhr, ajaxOptions, thrownError){
            alert(ajaxOptions)
        }
    });
});

Whatever i try, the success handler doesn't get executed. I get error handler instead. I tried with jsonpCallbak: "callback", jsonpCallback: "?", param: "callback" and other values too but without success. I have to use ONLY javascript without the support any server side scripting language (no aps, no php, etc.) Did someone get this service working in his site? Any suggestion would be really appreciated!

2 Answers 2

3

I find jQuery JSON API not suitable for this kind of JSON response that provides BlastCasta service. It assigns JSON to a custom variable, specified in URL, and doesn't uses callback functionality JSONP operates with. For example this URL: http://www.blastcasta.com/feed-to-json.aspx?feedUrl=http%3A//xml.corriereobjects.it/rss/homepage.xml&param=rssFeed will return following response:

rssFeed = { "rss": { "channel": /*...*/}}

So, script injection technic may be used:

/* URL of the BlastCasta service and his parameters:
  feedUrl :== escaped URL of interest (RSS Feed service)
  param   :== javascript variable name which will receive parsed JSON object */
var url = "http://www.blastcasta.com/feed-to-json.aspx"
  +"?feedUrl=http%3A//xml.corriereobjects.it/rss/homepage.xml"
  +"&param=rssFeed";

/* since the service declares variable without var keyword,
   hence in global scope, lets make variable usage via window object;
   although you can write param=var%20rssFeed" in the URL :) */
window.rssFeed = null;

$.getScript(url, function() {
  /* script is loaded, evaluated and variable is ready to use */
  console.dir(window.rssFeed);

  /* some feeds are huge, so free the memory */
  window.rssFeed = null;
});
Sign up to request clarification or add additional context in comments.

1 Comment

Well, BlastCasta then doesn't return a JSON response, technically speaking. It returns JS script instead.
1

Update:

here's an example that works for your code:

$.getJSON("http://www.blastcasta.com/feed-to-json.aspx?feedUrl=http://xml.corriereobjects.it/rss/homepage.xml&param=?", function(data) {
    console.dir(data);
});

problem is, that I get some javascript errors with returning json:

see this jsfiddle

2 Comments

Did you read my question? I wrote i cannot use php, so i cannot use the basic proxy provided with examples.
Thanks, i'll contact the webmaster and ask to fix the xml-to-json- converter

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.