php - 在源服务器上设置 Access-Control-Allow-Origin header

标签 php jquery apache rss cors

我正在使用 $.get 解析 jQuery 中的 RSS 提要,代码与此类似:

$.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...
    });
});

但是,由于单一来源政策,我收到以下错误:

No 'Access-Control-Allow-Origin' header is present on the requested resource.

幸运的是我可以访问源服务器,因为这是我自己动态创建的 RSS 提要。

我的问题是:如何在源服务器上设置 Access-Control-Allow-Origin header ?

编辑

我正在使用 PHP,我认为我的网络服务器是 Apache。

最佳答案

在 php 中正确设置:

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

关于php - 在源服务器上设置 Access-Control-Allow-Origin header ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22665280/

相关文章:

php - 如何查看在 codeigniter 中具有相同字段名称的连接表中的数据

php - 在 PHP 的 for 循环中使用模式

javascript - 在每个输入框的上边缘添加数字

javascript - 使用 jQuery 在部分进入视口(viewport)时旋转 SVG

javascript - 如何从JQuery AJAX生成的HTML数据中获取属性id? JavaScript

apache - mod_rewrite 帮助更改基于 URI 的内容处置

javascript - 使用 PHP 刷新后保留选择选项

php - 哪一个更好?使用您自己的加密算法还是使用 md5/sha1?

java - 似乎无法让从我的 Android 应用程序发送的 http 获取参数显示在我的 PHP 页面上

apache - 未知目录的重写规则