简体   繁体   English

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

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

This seems to be a pretty common question on here, and I've through a couple dozen threads on the topic. 这似乎是一个很普遍的问题,我已经通过了数十个关于该主题的话题。 However, none of the responses have worked for me so far. 但是,到目前为止,没有任何回应对我有用。 Basically I have a page with a jQuery/AJAX script that pulls a couple 基本上我有一个带有jQuery / AJAX脚本的页面

elements from an external (cross-domain) page. 外部(跨域)页面中的元素。

I've tried putting this in my .htaccess file: 我尝试将其放在我的.htaccess文件中:

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

as well as: 以及:

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

but no luck. 但没有运气。 My AJAX call is: 我的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.');
    }
});

Everything works perfectly when I run the page from my desktop, but from the actual hosted server, the console error in Chrome reads: 当我从桌面上运行页面时,一切工作正常,但是从实际的托管服务器上,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. 

Any ideas? 有任何想法吗?

On my server I had to explicitely set the url in my vhost directory directive: 在我的服务器上,我必须在vhost目录指令中显式设置url:

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

on the site that will recieve the request. 在将收到请求的网站上。

暂无
暂无

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

相关问题 XMLHttpRequest无法加载,不存在“ Access-Control-Allow-Origin”标头(无法在JavaScript / jQuery中读取Ajax响应) - XMLHttpRequest cannot load, No 'Access-Control-Allow-Origin' header is present (Unable to read Ajax response in JavaScript/jQuery ) XMLHttpRequest无法加载。 请求的资源上不存在“Access-Control-Allow-Origin”标头。 因此不允许原点访问 - XMLHttpRequest cannot load. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin is therefore not allowed access XMLHttpRequest无法加载“…所请求的资源上没有&#39;Access-Control-Allow-Origin&#39;头。” — jQuery - XMLHttpRequest cannot load “ …No 'Access-Control-Allow-Origin' header is present on the requested resource.” — Jquery XMLHttpRequest无法加载[archivo]。 所请求的资源上没有“ Access-Control-Allow-Origin”标头。 起源[dominio] - XMLHttpRequest cannot load [archivo]. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin [dominio] XMLHttpRequest无法加载。 Access-Control-Allow-Origin不允许起源 - XMLHttpRequest cannot load. Origin is not allowed by Access-Control-Allow-Origin Wampserver XMLHttpRequest无法加载所请求的资源上不存在“ Access-Control-Allow-Origin”标头 - Wampserver XMLHttpRequest cannot load No 'Access-Control-Allow-Origin' header is present on the requested resource XMLHttpRequest无法加载数据。 请求的资源上不存在“ Access-Control-Allow-Origin”标头 - XMLHttpRequest cannot load data. No 'Access-Control-Allow-Origin' header is present on the requested resource 无法为No&#39;Access-Control-Allow-Origin&#39;标头加载XMLHttpRequest - XMLHttpRequest cannot load for No 'Access-Control-Allow-Origin' header XMLHttpRequest无法加载…所请求的资源上没有“ Access-Control-Allow-Origin”标头 - XMLHttpRequest cannot load…No 'Access-Control-Allow-Origin' header is present on the requested resource Google Translate API:无法加载XMLHttpRequest。 Access-Control-Allow-Origin不允许来源http://test.dyndns.org - Google Translate API: XMLHttpRequest cannot load. Origin http://test.dyndns.org is not allowed by Access-Control-Allow-Origin
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM