第一个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