第一個Ajax請求接收響應,但不包括包含標頭的第二個響應。我如何允許標題包含在跨域Ajax請求中。允許跨域ajax請求中的標頭
注 - 我想我需要做一個服務器端的變化,也https://stackoverflow.com/a/32140436/1032531這麼說,但並沒有說如何使這些變化。此外,我不尋找一個jQuery唯一的解決方案。
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Testing</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.js" type="text/javascript"></script>
<script type="text/javascript">
$(function(){
$.ajax({
type:'POST',
url:'http://otherdomain.example.com/ajax.php',
})
$.ajax({
type:'POST',
url:'http://otherdomain.example.com/ajax.php',
headers: {"X-Test-Header": "test-value"},
})
});
</script>
</head>
<body></body>
</html>
FF響應於第二Ajax請求:
跨源請求封鎖:同源策略不允許讀取 遠程資源在http://otherdomain.example.com/ajax.php。 (原因:缺少令牌「×檢驗報頭」在CORS頭 從CORS預檢信道的訪問控制允許報頭')。
鉻響應第二爲:
的XMLHttpRequest不能加載http://otherdomain.example.com/ajax.php。 預檢響應中的訪問控制 - 允許 - 標題不允許請求標頭字段X-Test-Header。 Apache是建立 爲
如下:
Header set Access-Control-Allow-Origin "*"
Header set Access-Control-Allow-Methods "GET, POST, PUT, DELETE, OPTIONS"
Header set Access-Control-Allow-Headers "Origin, X-Requested-With, Content-Type, Accept, Authorization, Client-Security-Token, Accept-Encoding"
謝謝,但正如我原來的帖子所見,我已經這樣做了。這是沒有經過的標題。 – user1032531