【发布时间】: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