【发布时间】:2011-11-17 10:30:44
【问题描述】:
我只是想从服务器上的其他站点之一获取 html 并将其打印在当前站点上。这基本上就是我正在做的事情:
// The object
var xmlhttp = new XMLHttpRequest();
// When a button is pressed, we get the html
function printJSON(action)
{
otherURL = "http://www.my.domain.com/other.php?action=" +action;
xmlhttp.open('GET',otherURL,true);
xmlhttp.send();
}
// and then print it in this div
xmlhttp.onreadystatechange = function
{
if(xmlhttp.readyState == 4 && xmlhttp.status == 200)
{
$('JSON_output').innerHTML = xmlhttp.responseText;
}
}
我收到的错误是:
XMLHttpRequest 无法加载 http://www.my.domain.com/other.php?action=SEARCH。 Access-Control-Allow-Origin 不允许来源http://my.domain.com。
这看起来很奇怪,因为这是服务器上的一个站点试图访问同一文件夹中的另一个站点。我的服务器有什么需要调整的吗?我需要设置 xmlhttp 中的属性吗?
干杯!
【问题讨论】:
标签: javascript ajax cross-domain access-control