1

I am trying to read yahoo news feed from SharePoint site and its a cross domain access. I am using mentioned code to access but getting below error, I have gone thru lots of sites and blogs but still no luck. (I am running this code in Chrome console)

Uncaught SyntaxError: Unexpected token <

$.ajax({
  type:"GET",
  url:"https://www.yahoo.com/news/rss/world",
  dataType: "jsonp",
  success: function(data){
    console.log(data);
  }
});

enter image description here

Please suggest!

sideshowbarker
  • 81,827
  • 26
  • 193
  • 197
Rishi Jagati
  • 626
  • 1
  • 6
  • 28

3 Answers3

9

Google API Feed is already deprecated.So try to use alternative like rss2json site to read rss that convert to json.

http://rss2json.com/

Example:

put your rss url like below

url: "https://api.rss2json.com/v1/api.json?rss_url=" + "https://www.yahoo.com/news/rss/world",

Code

var url= 'https://www.yahoo.com/news/rss/world';
$.ajax({
  type: 'GET',
  url: "https://api.rss2json.com/v1/api.json?rss_url=" + url,
  dataType: 'jsonp',
  success: function(data) {
    console.log(data.feed.description);    
    console.log(data);
  }
});

Here is the working jsfiddle:http://jsfiddle.net/yvzSL/1406/

I think it should helps you

selvarajmas
  • 1,623
  • 13
  • 20
0

As i can see from the API, the data present is not json and hence you get the the following error

Change the dataType to xml

$.ajax({
  type:"GET",
  url:"https://www.yahoo.com/news/rss/world",
  dataType: "xml",
  success: function(data){
    console.log(data);
  }
});

However you may face the CORS error if the API doesnt' have Access control headers set

Shubham Khatri
  • 270,417
  • 55
  • 406
  • 400
  • True, it gives me CORS error. How can I achieve this? Do I need to go for another feed which support json dataType? – Rishi Jagati Apr 16 '17 at 07:23
  • You need to go for an API that has Access-Control-Allow-Origin headers set for its website or you need to request for the same. XML or JSON data won't make a difference – Shubham Khatri Apr 16 '17 at 07:25
0

if you are getting Cors origin , access denied or you are not allowed to get these data, the best choice will be Parsing the data after hitting an http get request by server side and then load it in your HTML page So the steps will be

  1. The ajax will request a local file
  2. then server side (local file which you requested) will do an http get request in order to pull the page
  3. this will get the whole of page, you can get your data by knowing the tags of you data
  4. finally parse your data yo json object and pass it to your ajax request
Basil Battikhi
  • 2,638
  • 1
  • 18
  • 34