I am using $.get
to parse an RSS feed in jQuery with code similar to this:
$.get(rssurl, function(data) {
var $xml = $(data);
$xml.find("item").each(function() {
var $this = $(this),
item = {
title: $this.find("title").text(),
link: $this.find("link").text(),
description: $this.find("description").text(),
pubDate: $this.find("pubDate").text(),
author: $this.find("author").text()
}
//Do something with item here...
});
});
However, due to the Single Origin Policy, I'm getting the following error:
No 'Access-Control-Allow-Origin' header is present on the requested resource.
Fortunately I have access to the source server, as this is my own dynamically created RSS feed.
My question is: how do I set the Access-Control-Allow-Origin header on my source server?
Edit
I'm using PHP and I think my webserver is Apache.
Set it right in the php:
header('Access-Control-Allow-Origin: *');
For apache, you simply add this to a .htaccess file in the same directory as the file you are trying to access remotely.
Header set Access-Control-Allow-Origin "*"
http://enable-cors.org/server_apache.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With