Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/280.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从PHP向GWT发送数组的问题_Php_Mysql_Gwt_Httprequest - Fatal编程技术网

从PHP向GWT发送数组的问题

从PHP向GWT发送数组的问题,php,mysql,gwt,httprequest,Php,Mysql,Gwt,Httprequest,我正在使用GWT(1.6)中的RequestBuilder,它成功地将字符串(格式化为日期)发送到web服务器上的PHP脚本。然后,我的PHP使用该字符串查询MySQL数据库。然后,我能够回显GWT成功解释的结果 我的问题是,我不只是想“回显”一个字符串。我想向GWT发送一个数组。这里的问题是GWT获取的是“Response”类型的对象,而不是数组 有人知道我能做什么吗?下面是一些代码: PHP CODE: <?php require_once('../scripts/config

我正在使用GWT(1.6)中的RequestBuilder,它成功地将字符串(格式化为日期)发送到web服务器上的PHP脚本。然后,我的PHP使用该字符串查询MySQL数据库。然后,我能够回显GWT成功解释的结果

我的问题是,我不只是想“回显”一个字符串。我想向GWT发送一个数组。这里的问题是GWT获取的是“Response”类型的对象,而不是数组

有人知道我能做什么吗?下面是一些代码:

 PHP CODE:

 <?php 
require_once('../scripts/config.php');

$date = $GLOBALS['HTTP_RAW_POST_DATA']; 

$query = mysql_query("SELECT * FROM eventcal WHERE eventDate = '$date'");

if (@mysql_num_rows($query)) {
    while ($r=@mysql_fetch_assoc($query)) { 
        $id = $r["id"];  
        $primary = $r["primary"];
        $secondary = $r["secondary"];
        $eventContent = $r["eventContent"];
        $region = $r["region"];

    }
}

$array = array("$id", "$primary", "$secondary", "$eventContent", "$region");

echo "$array";

 ?>
我知道我可以使用JSON,但我试过了,但没能让它工作。有什么想法吗

谢谢…

echo“$array”将只输出“array”或类似内容。您可以查看发送回JSON或XML,例如使用

我可以想象,您可以在GWT中非常轻松地解析它—请参见行
echo“$array”将只输出“array”或类似内容。您可以查看发送回JSON或XML,例如使用


我可以想象你可以在GWT中很容易地解析它-请参见

在我看来,JSONParser只能将字符串解析为JSON值…我在这方面错了吗?我想我会尝试按照你的建议使用XML,并以此作为指导:是的,它确实解析字符串。这就是你想要的。在PHP中,将数组转换为JSON字符串,然后在GWT中,将该JSON字符串解析回数据结构。我会选择这一点而不是XML——它应该更简单。在我看来,JSONParser只能将字符串解析为JSON值……我错了吗?我想我会尝试按照您的建议使用XML,并以此作为指导:是的,它确实解析字符串。这就是你想要的。在PHP中,将数组转换为JSON字符串,然后在GWT中,将该JSON字符串解析回数据结构。我会选择它而不是XML—它应该更简单。
 public void onChange(Widget sender) {
 lb.setText("Date selected: " + calendar.getDate());
 SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
 String current = df.format(calendar.getDate());

 RequestBuilder builder = new RequestBuilder(RequestBuilder.GET,   URL.encode("http://www.kbehr.com/calendar/view_duty.php"));

try {
  builder.sendRequest(current, new RequestCallback(){
    public void onError(Request request, Throwable exception) {
      requestFailed(exception);
    }

    public void onResponseReceived(Request request, Response response) {

        String responseText = response.getText();
        try {
          processResults(responseText);
        } catch (Exception e) {
          Window.alert(responseText);
        }

    }});
}catch (RequestException ex) {
  requestFailed(ex);
}    

 }});
 fp.add(calendar);
 fp.add(lb);  

 }

 private void processResults(String something){

  // process the array

 }
echo json_encode($array);