Tôi đang cố gắng thực hiện Yêu cầu trang web chéo bằng cách sử dụng Trình xây dựng yêu cầu GWT mà tôi chưa thể làm việc đó. Như bạn có thể thấy, đây là một phần của Dự án mẫu GWT và tôi đã trải qua https://developers.google.com/web-toolkit/doc/latest/tutorial/Xsite. Nhưng tôi vẫn còn thiếu cái gì đó.GWT RequestBuilder - Yêu cầu trang web chéo
Tôi đang đăng mã ở đây. Tôi đang thiếu gì ..?
package com.gwt.reqbuilder.client;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.http.client.Request;
import com.google.gwt.http.client.RequestBuilder;
import com.google.gwt.http.client.RequestCallback;
import com.google.gwt.http.client.RequestException;
import com.google.gwt.http.client.Response;
import com.google.gwt.http.client.URL;
import com.google.gwt.user.client.Window;
public class GWTRequestBuilder implements EntryPoint
{
private static final String JSON_URL = "http://localhost:8000/?q=ABC&callback=callback125";
public void onModuleLoad()
{
GWTPOSTHTTP();
}
public void GWTPOSTHTTP()
{
String postUrl="http://localhost:8000";
String requestData="q=ABC&callback=callback125";
RequestBuilder builder = new RequestBuilder(RequestBuilder.POST, postUrl);
try {
builder.sendRequest(requestData.toString(), new RequestCallback()
{
public void onError(Request request, Throwable e)
{
Window.alert(e.getMessage());
}
public void onResponseReceived(Request request, Response response)
{
if (200 == response.getStatusCode())
{
Window.alert(response.getText());
} else {
Window.alert("Received HTTP status code other than 200 : "+ response.getStatusText());
}
}
});
} catch (RequestException e) {
// Couldn't connect to server
Window.alert(e.getMessage());
}
}
}
Tôi đang tìm kiếm một giải pháp như thế này, tôi không muốn sử dụng JS nguyên gốc trong GWT Java. [Xin lỗi jonasr, tôi thực sự thích ý tưởng tiêu đề này] –