如何从解析json_encode到ajax jquery获取数据

时间:2014-08-05 08:40:15

标签: php ajax codeigniter json

//this is views file in codeigniter
$(".saving").click(function(){
    var id_member = $("#code_member").val();
    $.ajax({
        url     : '<?=site_url();?>show_joinmember/',
        type    : 'post',
        dataType: "json",
        data    : {'id_member':id_member},
        success : function(data){                           
            alert(data);
        }
    });
});



function show_joinmember(){
    $id  = $this->input->post('id_member');
    $qry = "select * from member where id_member = $id";
    $Sql = $this->db->query($qry)->result();
    foreach ($Sql as $r){
        $r->value  = $r->vendor_acct;
        $r->id     = $r->apinvoice_id;
        $row_set[] = $r;        
    }
    echo json_encode($row_set); 
}

结果提醒(数据)

  

[object Object],[object Object],[object Object],[object   对象],[对象对象],[对象对象],[对象对象],[对象   对象],[对象对象],[对象对象],[对象对象],[对象   对象],[对象对象],[对象对象],[对象对象],[对象   对象],[对象对象]

1 个答案:

答案 0 :(得分:0)

使用result_array()代替result()

$this->db->query($qry)->result();
像这样

$Sql = $this->db->query($qry)->result_array();
    foreach ($Sql as $r){
        $r['value']  = $r['vendor_acct'];
        $r['id']     = $r['apinvoice_id'];
        $row_set[] = $r;        
    }
 echo json_encode($row_set);