ajax처리 후 data반환 시 문자열로 받는 문제때문에 질문드립니다.
본문
a.php에서 ajax를 통해 post값을 전달해 b.php에서 post 값으로 계산 후 반환을 하려고 했습니다.
값은 배열로 반환이 목표입니다.
그래서 echo 결과값; 으로 하면 a.php에 ajax에 data에 담기는 것은 배열이 아닌 결과값이라는 문자열이 반환 되어 저장됩니다.
결과값 배열을 data에 반환할려면 어뜩게 해야되나요??
답변 3
그누에서는
$result = sql_query($sql);
while($row = sql_fetch_array($result)){
$arr[] = $row;
}
형식입니다
$result = sql_query($sql);
while($row = sql_fetch_array($result)){
$arr[] = $row;
}
형식입니다
// b.php
$a = array('a'=>'b');
echo json_encode($a);
이렇게 하시면 됩니다.
!-->
while($row = mysql_fetch_assoc($result)){
$myjsons[] = json_encode(array($row));
}
echo json_encode($myjsons);
이렇게 루프돌면서 담아야 합니다
$myjsons[] = json_encode(array($row));
}
echo json_encode($myjsons);
이렇게 루프돌면서 담아야 합니다
답변을 작성하시기 전에 로그인 해주세요.