0
你好我試圖ajax跨域調用,但有問題的標題。我跟着很多教程,但我不能讓它工作。不能得到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這只是工作。我錯過了什麼嗎?在Mozilla Firefox和谷歌Chrome瀏覽器存在問題,選項和405不允許的方法
問題是您的服務器沒有處理OPTIONS請求。 –
以及如何處理它? –
https://developer.mozilla.org/zh-CN/docs/HTTP/Access_control_CORS –