Read RSS XML in javascript (cross domain)

ajax, javascript, jquery, rss, xml

Solution

$.getJSON("//ajax.googleapis.com/ajax/services/feed/load?v=1.0&callback=?", {
    num: 10,
    q: url
}).done(function (data) {
    console.log(data);
});

Notes:

- You're overdoing it. Don't try to specify information on the client side that the server actually has to supply (content type, allow origin headers, data type).

- You don't want XML, you want JSON.

- The name for cross-origin JSON requests is JSONP.

- jQuery implements that for you if you use the `getJSON()` API method. You don't have to do anything besides adding `"callback=?"` to the URL.

- Use jQuery Deferred callbacks (`then`, `done`, `fail` and `always`). They allow your code to become a lot more flexible.

- Have a look at the documentation, too. https://developers.google.com/feed/v1/jsondevguide

Problem

I want to read rss(xml) file but without using google rss feed. i have try jsonp but it download the file and it throw a error "Uncaught SyntaxError: Unexpected token < " ``` $.ajax({ type: "GET", url:'https://news.google.com/?output=rss', //url: document.location.protocol + '//ajax.googleapis.com/ajax/services/feed/load?v=1.0&num=1000&callback=?&q=' + encodeURIComponent(url), dataType: "xml", contentType: "text/xml; charset=utf-8", headers: { "Access-Control-Allow-Origin":"*",}, success: function(xml) { alert("success"); } }); ``` plz guys help me..

Original source