我收到以下錯誤:
加載資源失敗:No'Access-Control-Allow-Origin '標題出現在請求的資源上。因此起源'域'不被允許訪問。 domain/api/login XMLHttpRequest無法加載api/login。請求的資源上沒有「Access-Control-Allow-Origin」標題。因此起源'域'不被允許訪問。出現錯誤加載資源失敗:在請求的資源上沒有「Access-Control-Allow-Origin」標頭
<script type="text/javascript">
function ajax_trial() {
var user_name="[email protected]";
var passcode = "1233";
var client_app_code = "1";
var ip_address = "someIP";
var json_string = '{"user_name" : "'+user_name+'","passcode":"'+passcode+'","client_app_code":"'+client_app_code+'","ip_address":"'+ip_address+'"}';
alert(json_string);
$.ajax({
'accept': 'application/json',
'contentType': 'application/json',
type: "POST",
dataType: "json",
'data': json_string,
cache: true,
crossDomain: true,
url: "/api/login",
success: function(data) {
alert("data "+data);
},
error: function(xhr, status, error) {
alert(xhr.responseText);
}
});
}
我的用戶休息的客戶端,這是代碼我得到當我發送JSON { 「USER_NAME」: 「[email protected]」, 「密碼」: 「1233」,」 client_app_code 「:」 1" , 「IP_ADDRESS」: 「1323」}
Request headers
User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko)
Chrome/31.0.1650.63 Safari/537.36
Origin: chrome-extension://hgmloofddffdnphfgcellkdfbfbjeloo
Content-Type: application/json
Accept: */*
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-US,en;q=0.8,it;q=0.6
Response headers
Server: Apache-Coyote/1.1
sessionId: 94c16db2-6bb8-11e3-a4e7-7845c4b4
Access-Control-Allow-Origin: *
Vary: Accept-Encoding
Content-Encoding: gzip
Content-Type: application/json
Transfer-Encoding: chunked
Date: Mon, 23 Dec 2013 09:57:06 GMT