3
我有一個RestEasy api,我需要提供對移動客戶端的所有http方法的訪問權限,所有這些請求都必須通過ajax發送。resteasy ajax請求
下面是客戶端代碼的例子:
var data = {
login: '[email protected]',
password: '123456'
};
$.ajax({
url: 'http://1.1.1.3:8080/api/admin',
type: 'POST',
contentType : 'application/json',
dataType: "json",
data: JSON.stringify(data),
success: function(){
console.log(arguments);
},
error: function(){
console.log('error')
}
});
這裏的服務器:
@POST
@Consumes("application/json")
@Produces("application/json")
public Response doLogin(User user) {...}
,這裏是錯誤:
XMLHttpRequest cannot load http://1.1.1.3:8080/api/admin. Origin http://stackoverflow.com is not allowed by Access-Control-Allow-Origin.
這裏是我的頭回答從本地服務器請求本地主機時
Access-Control-Allow-Cred... true
Access-Control-Allow-Orig... http://1.1.1.3:8080 //request sent from http://1.1.1.3:8080
Access-Control-Expose-Hea... X-Test-2, X-Test-1
Content-Length 1136
Content-Type text/html;charset=utf-8
Date Wed, 19 Dec 2012 17:54:19 GMT
Server Apache-Coyote/1.1
PS:通過一般的http請求,一切正常。
我錯過了什麼?