在AppFog上部署了Spring + Jersey + Access-Control-Allow-Origin

时间:2013-03-30 19:05:54

标签: jquery spring servlets jersey

我不确定为什么在使用Ajax对JQuery进行服务器调用时抛出此错误。

我的服务器代码是

@POST
@Path("/update")
@Produces({ "application/json "})
public Response update(String json) {
    ......
    ResponseBuilder builder = Response.ok("test");
    builder.header("Access-Control-Allow-Origin", "*");
    builder.header("Access-Control-Allow-Headers", "*");
    return builder.build();

我的Jquery代码是

var URL = "http://........";


$.ajax
({
    type: "POST",
    //the url where you want to sent the userName and password to
    url: URL,
    dataType: 'json',

    success: function (data) {
    alert("ok"); 
    }
});

注意:相同的代码在Google App Engine上正常运行.....

1 个答案:

答案 0 :(得分:1)

尝试使用Firefox,Safari或IE。我有同样的问题。