dongtao9095
2011-10-19 05:00
浏览 32

将GWT输入发布到PHP页面

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.

图片转代码服务由CSDN问答提供 功能建议

我有一个带输入的GWT应用程序(比如姓名,地址,电子邮件)。 用户输入所有必填字段并按下提交按钮后,PHP页面将显示GWT应用程序的输入。 如何将我的GWT应用程序连接到php? 我现在正在使用Request Builder。 我是否还必须使用XML将GWT输入传递给PHP? 请帮忙。 我刚刚开始在这里学习GWT。

提前致谢。

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • duanmu5641 2011-10-19 11:05
    已采纳

    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']
    
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题