Setting the Access-Control-Allow-Origin header on the source server

I use $.getto parse an RSS feed in jQuery with code like 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 a single-origin policy, I get the following error:

No header "Access-Control-Allow-Origin" 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 to set the Access-Control-Allow-Origin header on the source server?

Edit

I am using PHP and I think my web server is Apache.

+4
source share
2 answers

apache .htaccess , , .

Header set Access-Control-Allow-Origin "*"

http://enable-cors.org/server_apache.html

+6

php:

header('Access-Control-Allow-Origin: *');
+7

Source: https://habr.com/ru/post/1533562/


All Articles