【问题标题】:Spring + Jersey + Access-Control-Allow-Origin deployed on AppFog部署在 AppFog 上的 Spring + Jersey + Access-Control-Allow-Origin
【发布时间】:2013-03-21 06:45:11
【问题描述】:

我不确定为什么在使用 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 上运行良好.....

【问题讨论】:

  • 很抱歉,如果它应该很明显但是 - 抛出的错误是什么?
  • 同一个 XMLHttpRequest 无法加载 http://....... Origin localhost 不被 Access-Control-Allow-Origin 所允许。

标签: jquery spring servlets jersey


【解决方案1】:

在 Firefox、Safari 或 IE 中尝试。我有同样的问题。

【讨论】:

    猜你喜欢
    • 2013-09-14
    • 1970-01-01
    • 2020-05-27
    • 2017-06-15
    • 2016-09-30
    • 2015-06-17
    • 2023-01-13
    • 2017-12-29
    • 1970-01-01
    相关资源
    最近更新 更多