dongshi9407
2012-05-21 20:22
浏览 77
已采纳

在GWT和PHP之间传递数据

I'm a newbie with GWT and PHP, and after reading some tutorials it's not clear for me how to efficiently exchange data between the GWT frontend and PHP backend. I successfully followed the Google tutorials where is suggested to use the RequestBuilder class to get data from PHP. But when I need to save the work done in GWT, how to efficiently pass the data to PHP? It's not clear for me how to use the RequestBuilder for this task. The solution that I found for now is

RequestBuilder builder = new RequestBuilder(RequestBuilder.POST, URL.encode(url));
    builder.setHeader("Content-Type", "application/json");
        try {
              Request request = builder.sendRequest("{\"done\":false,\"description\":\"Some text\",\"priority\":0}", new RequestCallback() {...

and in PHP side

$arr = json_decode(file_get_contents("php://input"),true);
$done = (int)$arr['done'];
$description = $arr['description'];
$priority = $arr['priority'];
mysql_query("INSERT INTO Tasks (done, description, priority)
    VALUES ($done, '$description', $priority)");

Is this the best approach? Have someone found a working example in the web? Every opinion is welcome...

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

我是GWT和PHP的新手,在阅读了一些教程之后,我不清楚如何有效地交换 GWT前端和PHP后端之间的数据。 我成功地遵循谷歌教程,建议使用RequestBuilder类从PHP获取数据。 当我需要保存GWT中完成的工作时,如何有效地将数据传递给PHP? 我不清楚如何 使用RequestBuilder执行此任务。 我现在找到的解决方案是</ p>

  RequestBuilder builder = new RequestBuilder(RequestBuilder.POST,URL.encode(url)); 
  builder.setHeader(“Content-Type”,“application / json”); 
尝试{
请求请求= builder.sendRequest(“{\”done \“:false,\”description \“:\”一些文字 \“,\”priority \“:0}”,新的RequestCallback(){... 
 </ code> </ pre> 
 
 

在PHP端</ p>

  $ arr = json_decode(file_get_contents(“php:// input”),true); 
 $ done =(int)$ arr ['done']; 
 $ description = $ arr ['  description']; 
 $ priority = $ arr ['priority']; 
mysql_query(“INSERT INTO Tasks(done,description,priority)
 VALUES($ done,'$ description',$ priority)”); \  n </ code> </ pre> 
 
 

这是最好的方法吗? H? 有人在网络上找到了一个有效的例子吗? 欢迎提出各种意见...... </ p> </ div>

1条回答 默认 最新

相关推荐 更多相似问题