JAVASCRIPT ajax , json , json_encode 구분별로 데이터 받기.

보내고 받는 쪽의 자바스크립  ( 클라이언트 )  ---------------
    function get_member_info(mode,code)
    {
        var comma_amount  = "";
        var ctmonth = "";
 
 
        $.ajax({
            type: "post"
            , dataType: "json"
            , url: "/ajax/test.php"
            , data: "_M_="+mode+"&code=" + code
            , success: function (data) {
 
                $.each(data, function (index, item) {
 
                    if( mode == 1)
                    {
                        $("#hphone").val(item.hphone);
                        comma_amount = addComma(item.amount) ;
                        $("#special_amount").val(comma_amount);
                        $("#memid").val(item.memid);
                        $("#order_date").val(item.order_date);
                        $("#memtemppw").val('0000');
                        $("#sdate").val(item.sdate);
                        $("#edate").val(item.edate);
                    }
                    else if ( mode == 2 )
                    {
                        ctmonth = item.ct_month * 1 ;
                        if( ctmonth > 0 )
                        {
                            ctmonth = item.ct_month + "개월";
                        }
                        else
                        {
                            ctmonth = "";
                        }
                        $("#ct_month").val(ctmonth);
                    }
                    else if ( mode == 3 )
                    {
                        comma_amount = addComma(item.calramount) ;
                        $("#calramount").val(comma_amount);
                    }
                });
 
            }
            , error: function (data) {
                //console.log(data)
                // alert("error 1");
            }
        });
    }








 
서버 측 내용 ( php ) -------------------------------
 
$get_mode	= $_POST['_M_'];
$code			= $_POST['code'];
 
$resultArr = array(); 
 
	array_push($resultArr, 
	array(
	 "code" =>  $code
	, "hphone" => $row->hphone
	, "amount" => $sum_price
	, "memid" => $row->memid
	, "order_date" => $sumorderdateymd
	, "sdate" => $row->sdate
	, "edate" => $row->edate
	) );
 
echo json_encode ( $resultArr );

답글 남기기

이메일 주소는 공개되지 않습니다. 필수 필드는 *로 표시됩니다