내가 자꾸 까먹어서 쓰는 개발 이야기/jQuery
PHP에서 jQuery로 JSON 배열 받아 사용하기
FIL.
2012. 8. 13. 17:35
728x90
<?
$arr[0] = array("A"=>"A", "B"=>"B");
$arr[1] = array("Z"=>"Z", "Y"=>"Y");
echo json_encode($arr);
?>
와 같이 리턴하는 경우 jQuery.post(또는 get)의 콜백함수에서 data 변수로 리턴 받는다 가정하면,
var dt = jQuery.parseJSON(data);
와 같이 해주면 dt는 일반 배열처럼 사용할 수 있게 된다!!!
출처 : http://stackoverflow.com/questions/3250623/php-array-to-js-array-with-jquery-and-json-encode