0
안녕하세요, 저는 도메인 간 콜백을 시도하고 있지만 헤더에는 문제가 있습니다. 나는 많은 튜토리얼을 따라 갔지만 나는 그저 작동하지 않는다.크롬 및 파이어 폭스에서 CORS가 작동하지 않습니다.
이 내가 갔을까요 얼마나 멀리입니다 :
<html>
<head>
<meta http-equiv="Access-Control-Allow-Origin" content="*">
</head>
<body>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js" ></script>
<script>
jQuery.support.cors = true;
$(document).ready(function() {
//this would be done in a common script file if you are going to
//make a lot of these calls
$.ajaxSetup({ type: 'POST', dataType: 'json', contentType: 'application/json', data: {} });
$('#btn').click(function() {
//call the web service with the button is clicked
$.ajax({ url: 'url_external',
data: '{ "some_data:data" }', //ensure the data is enclosed in a quote
success: function (data) {
alert('here...success');
},
complete: function (data) {
alert('here');
}
});
//return false to avoid a postback
return false;
});
});
</script>
<div>
<button id='btn'>Load It</button>
<div id='sayit'></div>
</div>
</body>
</html>
그리고 IE9에서이에서만 작동합니다. 내가 놓친 게 있니?
<?php
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: POST, GET, OPTIONS, PUT, DELETE');
header('Access-Control-Allow-Headers', 'Content-Type');
이것은 당신의 url_external
에 CORS Ajax 요청을 할 수 있습니다 : 모질라 파이어 폭스와 구글 크롬에서
문제는 서버가 OPTIONS 요청을 처리하지 못한다는 것입니다. –
그리고 어떻게 처리할까요? –
https://developer.mozilla.org/en-US/docs/HTTP/Access_control_CORS –