JSONP PHP数组空

时间:2014-04-25 10:44:55

标签: java php jsonp

我试图通过我的网页使用PHP脚本从JSONP获取数据:

//connection and query above
 ...

 while($r=mysqli_fetch_array($result)){
    //Add the fetched vale to $json array
    $json[] = $r;
     // Content type
  header("Content-type: application/json");
    echo "$callback({email: 'Message from Server.php'});";

  }



  // Content type
  header("Content-type: application/json");

  //JSONP - Make it as JSONP object


echo $_GET['callback']."(".json_encode($json).")";

my echo "$callback({email: 'Message from Server.php'});";< --- works

但我的 echo $_GET['callback']."(".json_encode($json).")";< ---返回null

当我在我的网页上调用脚本时,例如" page / callback.php"

我在浏览器中获得以下输出:

    ({email: 'Message from Server.php'});([{"0":"3","ID":"3","1":"dome","username":"dome","2":"vjvhrOWZYTq3qbrYfoE13A==","passwort":"vjvhrOWZYTq3qbrYfoE13A==","3":"mii@googlemail.com","email":"mii@googlemail.com","4":"0","active":"0","5":"hu","loc":"hu"}]

)

它包含 - > " ["和"]"

我的Java脚本是GWT:

        JsonpRequestBuilder jsonp = new JsonpRequestBuilder();
    jsonp.requestObject(URL.encode("http://webpage/callback.php?callback=test_clbk"), new AsyncCallback<JSONreceiver>() {
        public void onFailure(Throwable throwable) {
            System.out.println(throwable.getMessage());
        }
        @SuppressWarnings("unused")
        public void onSuccess(JSONreceiver result) {
            System.out.println(result.getResult());
        }
    });

0 个答案:

没有答案