javascript - Read news from feed using jquery (cross domain), Getting Uncaught SyntaxError: Unexpected token < error - St

I am trying to read yahoo news feed from SharePoint site and its a cross domain access. I am using ment

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:"",
  dataType: "jsonp",
  success: function(data){
    console.log(data);
  }
});

Please suggest!

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./news/rss/world",
  dataType: "jsonp",
  success: function(data){
    console.log(data);
  }
});

Please suggest!

Share edited Dec 31, 2019 at 9:58 sideshowbarker 88.4k29 gold badges215 silver badges212 bronze badges asked Apr 16, 2017 at 7:13 Rishi JagatiRishi Jagati 6261 gold badge6 silver badges28 bronze badges 5
  • Is the day you are getting from the API JSON – Shubham Khatri Commented Apr 16, 2017 at 7:15
  • have you tried to remove the datatype ? im sure of that the type will not be json – Basil Battikhi Commented Apr 16, 2017 at 7:18
  • Why not use an RSS feed reader rather than making a GET request? See some suggestions here: stackoverflow./questions/10943544/… – BenShelton Commented Apr 16, 2017 at 7:29
  • try to use other alternatives of Google API Feed to get rss data – selvarajmas Commented Apr 16, 2017 at 7:58
  • @Rishi Jagati, Check my answer. – Ataur Rahman Munna Commented Apr 16, 2017 at 8:03
Add a ment  | 

3 Answers 3

Reset to default 9

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

http://rss2json./

Example:

put your rss url like below

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

Code

var url= 'https://www.yahoo./news/rss/world';
$.ajax({
  type: 'GET',
  url: "https://api.rss2json./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/yvzSL/1406/

I think it should helps you

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./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

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

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742295276a4416992.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信