2012-08-14 29 views
1

我在我的網站上使用CORS進行跨域通話。雖然,圖片中顯示的響應標題對我來說似乎很好,但我沒有收到任何迴應。它仍然空白或返回響應。任何人都可以預測我的方法中的錯誤,看到附加的圖像?實施CORS時未獲得響應

在服務器端,我使用的這個片段

header("Access-Control-Allow-Origin: *"); 
    header("Access-Control-Allow-Credentials: true "); 
    header("Access-Control-Allow-Methods: GET, POST"); 
    header("Access-Control-Allow-Headers: Content-Type, Depth, User-Agent, X-File-Size, X-Requested-With, If-Modified-Since, X-File-Name, Cache-Control"); 

而在客戶端,我有: -

function getXMLHTTPRequest() { 
try { 
req = new XMLHttpRequest(); 
} catch(err1) { 
try { 
req = new ActiveXObject("Msxml2.XMLHTTP"); 
} catch (err2) { 
try { 
req = new ActiveXObject("Microsoft.XMLHTTP"); 
} catch (err3) { 
req = false; 
} 
} 
} 
return req; 
} 

var http899 = getXMLHTTPRequest(); 

http899.open("GET", modurl, true); 
http899.setRequestHeader('Content-Type', 'text/html'); 
http899.onreadystatechange = useHttpResponse899; 
http899.send(null); 

enter image description here

+0

請看看到期時間。它的1981年。這可能是一個問題嗎? – 2012-08-14 14:20:42

+0

似乎在這裏類似的問題:http://serverfault.com/questions/446152/litespeed-enable-access-control-allow-origin-no-response-header-on-cors-request – 2012-11-07 16:01:30

+1

@JoeCoderGuy在解決我的問題之後,我寫了這個..檢查出http://stackoverflow.com/questions/11964178/implementing-cross-domain-communication-between-sites-through-cors-using-php-and/11964339#11964339 – 2012-11-08 07:31:53

回答

2

不一定是完整的答案,但我認爲某些瀏覽器不接受「Access-Control-Allow-Origin」標題中的多個條目。我不知道Firefox是否是其中之一。

也許嘗試將請求的「Origin」標題複製到響應的「Access-Control-Allow-Origin」中,如果它位於要接受的起源列表中?

+1

是的,我刪除了重複進入,仍然面臨同樣的問題! – 2012-08-14 14:09:55

1

我的服務器有問題。當我在不同的服務器上嘗試相同的代碼時,它工作正常!我使用共享主機,它被服務提供商禁用。