簡體   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