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
3 Answers
Reset to default 9Google 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
- The ajax will request a local file
- then server side (local file which you requested) will do an http get request in order to pull the page
- this will get the whole of page, you can get your data by knowing the tags of you data
- finally parse your data yo json object and pass it to your ajax request
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742295276a4416992.html
评论列表(0条)