来自gwt的呼叫操作->;访问控制允许源不允许URL
我的grails应用程序提供了一个应该向gwt客户机提供json数据的操作。 如果我从gwt调用该操作,我将在浏览器中看到以下错误:来自gwt的呼叫操作->;访问控制允许源不允许URL,gwt,grails,Gwt,Grails,我的grails应用程序提供了一个应该向gwt客户机提供json数据的操作。 如果我从gwt调用该操作,我将在浏览器中看到以下错误: XMLHttpRequest cannot load http://localhost:8080/myApp/myDomain/myAction/123. Origin http://127.0.0.1:8888 is not allowed by Access-Control-Allow-Origin. 这个错误意味着什么?我怎样才能解决这个问题呢 GWT代
XMLHttpRequest cannot load http://localhost:8080/myApp/myDomain/myAction/123.
Origin http://127.0.0.1:8888 is not allowed by Access-Control-Allow-Origin.
这个错误意味着什么?我怎样才能解决这个问题呢
GWT代码:
String url = "http://localhost:8080/myApp/myDomain/myAction/123"
RequestBuilder builder = new RequestBuilder(RequestBuilder.POST, url);
builder.sendRequest("", new RequestCallback() {
@Override
public void onResponseReceived(Request request, Response response) {
GWT.log("Response: "+response.getText());
}
@Override
public void onError(Request request, Throwable exception) {
GWT.log("ERROR: " + exception.getMessage());
}
});
grails代码(操作):
您正在尝试在不同的域上执行请求。根据“访问控制允许来源”,您只能在来源域中执行请求
def myAction = {
def data = ...
render(contentType:"text/json"){data}
}