我正在使用 $.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/