Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ajax/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ssh/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 试图从同一域中的站点获取资源时,访问控制允许源错误?_Javascript_Ajax_Cross Domain_Access Control - Fatal编程技术网

Javascript 试图从同一域中的站点获取资源时,访问控制允许源错误?

Javascript 试图从同一域中的站点获取资源时,访问控制允许源错误?,javascript,ajax,cross-domain,access-control,Javascript,Ajax,Cross Domain,Access Control,我只是想从服务器上的一个其他站点获取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; xml

我只是想从服务器上的一个其他站点获取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。访问控制不允许原点允许原点

这似乎很奇怪,因为这是服务器上的一个站点试图访问同一文件夹中的另一个站点。我的服务器上有什么需要调整的吗?需要设置xmlhttp中的属性吗

干杯

和是两个不同的域,请注意www根据

如果www.my.domain.com和my.domain.com指向同一个地方,最简单的解决方案是使其他URL相对;以/other.php?action=开始;这样,它将始终与您的页面位于同一个域中


如果没有,请指向同一个位置,有一个更复杂的解决方案,涉及服务器输出名为;的附加头

你是个大帅哥,谢谢。我不确定“域名”到底意味着什么。现在我知道了,并且有了一个工作场所!一分钟后我就可以接受这个答案了。