첫 번째 Ajax 요청은 응답을 수신하지만 헤더를 포함하는 두 번째 응답은 수신하지 않습니다. 헤더가 크로스 도메인 Ajax 요청에 포함되도록하려면 어떻게해야합니까?크로스 도메인 아약스 요청에서 헤더 허용
주 - 서버 측 변경이 필요할 것으로 예상하고 https://stackoverflow.com/a/32140436/1032531도 그렇게 말하지만 변경 방법은 설명하지 않습니다. 또한, 나는 jQuery 유일한 해결책을 찾고 있지 않다. 두 번째 Ajax 요청에
<!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 응답 : 차단
크로스 원산지 요청 : 동일한 기원 정책 http://otherdomain.example.com/ajax.php에서 원격 자원을 읽어 허용하지 않습니다. (이유 : CORS 헤더의 'x-test-header'가 누락되었습니다. CORS 프리 플라이트 채널의 '액세스 제어 허용 헤더').
XMLHttpRequest를로드 할 수 http://otherdomain.example.com/ajax.php :
크롬은 두 번째로 응답합니다. 요청 헤더 필드 X- 테스트 - 헤더가 허용되지 않습니다. 프리 플라이트 응답의 액세스 제어 허용 헤더. 아파치는
은 다음
로 설정됩니다 : 당신은 htaccess로 규칙을 사용하여이 오류를 제거 할 수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