簡體   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