将 GWT 输入发布到 PHP 页面

发布于 2024-12-11 06:05:59 字数 179 浏览 0 评论 0原文

我有一个带有输入的 GWT 应用程序(例如姓名、地址、电子邮件)。用户输入所有必填字段并按提交按钮后,PHP 页面将显示来自 GWT 应用程序的输入。如何将我的 GWT 应用程序连接到 php?我现在正在使用请求生成器。我是否仍然需要使用 XML 将 GWT 输入传递给 PHP?请帮忙。我刚刚开始在这里学习GWT。

提前致谢。

I have a GWT app with inputs (let's say Name, Address, Email). After user input all the required fields and press submit button, a PHP page will display the inputs from the GWT app. How can I connect my GWT app to php? I'm using Request Builder now. Do I still have to use XML to pass the GWT inputs to PHP? Please help. I'm just starting to learn GWT here.

Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

对你而言 2024-12-18 06:05:59

实际上,您不需要 RequestBuilder 来完成类似的事情。
如果您重定向到 PHP url 并将输入附加为 GET 参数就足够了。
例如,在点击处理程序中,您可以执行类似的操作:

submitButton.addClickHandler(new ClickHandler() {
    public void onClick(ClickEvent event) {
        String linkURL = "somePage.php?name="+name+"&address="+address+"&email="+email;
         Window.Location.assign(linkURL);
    }
});

然后在 PHP 页面中,您可以通过以下方式检索参数:

$name = $_GET['name'];
$address = $_GET['address'];
$email = $_GET['email'];

更新

如果您想使用 RequetBuilder,则必须执行类似的操作:

submitButton.addClickHandler(new ClickHandler() {
    public void onClick(ClickEvent event) {
        RequestBuilder request = new RequestBuilder(POST,PHP_URL);
        JSONObject jsonValue = new JSONObject();
        jsonValue.put("name", new JSONString(name));
        jsonValue.put("address", new JSONString(address));
        jsonValue.put("email", new JSONString(email));
        request.setHeader("Content-Type", "application/json");
        request.sendRequest(jsonValue.toString(),new RequestCallback() {
            @Override
            public void onResponseReceived(Request request, Response response) {
                if (200 == response.getStatusCode()) {
                     //retrieve a uniqueid or so and redirect to the PHP page which displays the infos
                } else {
                   // displayError("Couldn't retrieve 

                }
            }

            @Override
            public void onError(Request request, Throwable exception) {
                 //displayError("Couldn't retrieve JSON");
            }
         });

    }
});

在服务器上,您只需访问全局 $_POST 变量即可获取值:

$name = @_POST['name']

You actually don't need RequestBuilder for something like that.
It would be sufficient if you redirect to the PHP url and append your inputs as GET parameters.
So for example in the click handler you can do something like that:

submitButton.addClickHandler(new ClickHandler() {
    public void onClick(ClickEvent event) {
        String linkURL = "somePage.php?name="+name+"&address="+address+"&email="+email;
         Window.Location.assign(linkURL);
    }
});

and then in the PHP page you can retrieve the parameters in this way:

$name = $_GET['name'];
$address = $_GET['address'];
$email = $_GET['email'];

Update

If you want to use RequetBuilder you have to do something like that:

submitButton.addClickHandler(new ClickHandler() {
    public void onClick(ClickEvent event) {
        RequestBuilder request = new RequestBuilder(POST,PHP_URL);
        JSONObject jsonValue = new JSONObject();
        jsonValue.put("name", new JSONString(name));
        jsonValue.put("address", new JSONString(address));
        jsonValue.put("email", new JSONString(email));
        request.setHeader("Content-Type", "application/json");
        request.sendRequest(jsonValue.toString(),new RequestCallback() {
            @Override
            public void onResponseReceived(Request request, Response response) {
                if (200 == response.getStatusCode()) {
                     //retrieve a uniqueid or so and redirect to the PHP page which displays the infos
                } else {
                   // displayError("Couldn't retrieve 

                }
            }

            @Override
            public void onError(Request request, Throwable exception) {
                 //displayError("Couldn't retrieve JSON");
            }
         });

    }
});

On the server you just access the global $_POST variable to get the values:

$name = @_POST['name']
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文