I need to get feed from third party with jQuery or javascript. I have this code in jQuery to read the rss xml feed in jQuery
$.ajax({
type: "GET",
url:'https://www.thirdpartysite.com/feed.xml',
dataType: "jsonp",
jsonp: false,
jsonpCallback: 'getFeed',
headers: { "Access-Control-Allow-Origin":"*",},
success: function(xml) {
console.log("success");
console.log(xml);
}
});
function getFeed(val){
console.log(val);
}
This is giving me "Uncaught SyntaxError: Unexpected token <" error in my console. However the following codes works fine (note cross domain feed access)
$.ajax({
type: "GET",
url:'http://mytestsite.com/myfeed.php',
dataType: "jsonp",
jsonp: false,
jsonpCallback: 'getFeed',
headers: { "Access-Control-Allow-Origin":"*",},
success: function(xml) {
console.log("success");
console.log(xml);
}
});
function getFeed(val){
console.log(val);
}
The code in myfeed.php is as below:
echo 'getFeed("<?xml version=\"1.0\" encoding=\"UTF-8\" ?><rss version=\"2.0\"><channel><title>W3Schools Home Page</title><link>https://www.w3schools.com</link><description>Free web building tutorials</description><item><title>RSS Tutorial</title><link>https://www.w3schools.com/xml/xml_rss.asp</link><description>New RSS tutorial on W3Schools</description></item><item><title>XML Tutorial</title><link>https://www.w3schools.com/xml</link><description>New XML tutorial on W3Schools</description></item></channel></rss>");';
It seems that we need to add the callback function while returning the the xml. However I don't have access to add that callbackfunction
Is there a way to make it work for xml rss feed.
Any help will be appreciated.
Thanks