문제

GWT (1.6)의 requestBuilder를 사용하여 문자열 (날짜 형식)을 내 웹 서버의 PHP 스크립트로 전송합니다. 그런 다음 내 PHP는 해당 문자열을 사용하여 MySQL 데이터베이스를 쿼리합니다. 그런 다음 결과를 반향 할 수 있으며 GWT에 의해 성공적으로 해석됩니다.

내 문제는 문자열을 "에코"하고 싶지 않다는 것입니다. 배열을 GWT로 돌려 보내고 싶습니다. 여기서 문제는 GWT가 배열이 아닌 유형의 '응답'의 객체를 얻는다는 것입니다.

내가 무엇을 할 수 있는지 아는 사람이 있습니까? 다음은 몇 가지 코드입니다.

 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";

 ?>

GWT 코드 (스 니펫) :

 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

 }

나는 JSON을 사용할 수 있다는 것을 알고 있지만, 그것을 시도하고 그것을 작동시킬 수 없었습니다. 어떤 아이디어?

감사...

도움이 되었습니까?

해결책

라인 echo "$array"; '배열'또는 이와 유사한 출력 만 출력합니다. 예를 들어 JSON 또는 XML을 다시 보내는 것을 볼 수 있습니다. json_encode(), 예를 들어

echo json_encode($array);

나는 당신이 GWT에서 이것을 아주 쉽게 구문 분석 할 수 있다고 생각합니다 - JSONPARSER

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top