繁体   English   中英

XMLHttpRequest无法加载。 不存在“ Access-Control-Allow-Origin”标头。 (阿帕奇/ jQuery的/ AJAX)

[英]XMLHttpRequest cannot load. No 'Access-Control-Allow-Origin' header is present. (Apache/jQuery/AJAX)

这似乎是一个很普遍的问题,我已经通过了数十个关于该主题的话题。 但是,到目前为止,没有任何回应对我有用。 基本上我有一个带有jQuery / AJAX脚本的页面

外部(跨域)页面中的元素。

我尝试将其放在我的.htaccess文件中:

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

以及:

<ifModule mod_headers.c>
    Header set Access-Control-Allow-Origin: *
</ifModule>  

但没有运气。 我的AJAX电话是:

$.ajax({
    type: 'GET',
    url: 'url', //I have the actual URL here of course
    cache: false,
    contentType: 'text/plain',
    dataType: 'html',
    crossDomain: true,
    success: function( data ) {
        //doing stuff with data in here
    }, error: function(jqXHR, textStatus, errorThrown) {
        alert('critical error. everything is exploding. abort mission.');
    }
});

当我从桌面上运行页面时,一切工作正常,但是从实际的托管服务器上,Chrome中的控制台错误显示为:

"XMLHttpRequest cannot load http://external_url.com. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://my_url.com' is therefore not allowed access. 

有任何想法吗?

在我的服务器上,我必须在vhost目录指令中显式设置url:

Header set Access-Control-Allow-Origin "http://mysite.mydomain.com"

在将收到请求的网站上。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM