繁体   English   中英

如何使用 jquery 在 ajax 中显示来自 CI controller 的 json_encoded 数据

[英]how to display json_encoded data from the CI controller in ajax with jquery

我想显示 CI controller 发送的 json_encoded 数据

public function single_member_info(){
    $selected_id=$this->input->post('selectedid');
    $data['member_data']=$this->db->get_where('member',array('member_id'=>$selected_id))->result();
    echo json_encode($data);
}  

Json数据在ajax成功部分单独显示(我想一一访问json数据)

 $(document).ready(function(){
      $('.show_data').click(function(){
          var selected_id=$(this).attr('id');
          $.ajax({
                  type: "POST",
                  url: '<?php echo base_url()?>Welcome/single_member_info',
                  data: {selectedid:selected_id},
                  success: function(data){
                console.log(data);
                }
          });
      });
});

在控制台 output 像这样

{"member_data":[{"member_id":"2","member_profile_id":"BD446F49452","status":"approved","first_name":"nagendra","last_name":"ks","gender":"1","email":"nagenfg@gmail.com","mobile":"8558453046","alternative_mobile":"","is_closed":"no","date_of_birth":"74884479200","height":"5.40","password":"7c4a8d09ca3744588562af61e59520943dc26494f8941b","profile_image":"[{\"profile_image\":\"profile_2.png\",\"thumb\":\"profile_2_thumb.png\"}]"}
$(document).ready(function(){
      $('.show_data').click(function(){
          var selected_id=$(this).attr('id');
          $.ajax({
                  type: "POST",
                  url: '<?php echo base_url()?>Welcome/single_member_info',
                  data: {selectedid:selected_id},
                  success: function(data){
                console.log(data);

                    var html = '';
                    var i;
                    for(i=0; i<data.length; i++){
                        html += '<tr>'+
                                '<td>'+data[i].member_data+'</td>'+
                                '</tr>';
                    }

               }
          });
      });
});


     $('#show_data').html(html);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM