传递json将数据从控制器编码到使用Codeigniter中的ajax进行查看

时间:2018-02-13 04:52:24

标签: php jquery json ajax codeigniter

我从控制器中选择数据,我想在视图中显示它。我想在bootstrap视图中显示它。我应该在哪里加载视图inmybootstrap模板:

$data['sidebar']='member/dokter/sidebar_psn';
$data['content']='member/dokter/odontogram';
$this->load->view('member/dokter/main',$data);

我的控制器:

$data['odontogram']=$this->m_pasien->DtOdontogram($id_pasien);
            echo json_encode($data);

结果:

{ “odontogram”:[ { “金粉”: “P53”, “posisi”: “C”, “kondisi”: “AMF”},{ “金粉”: “P61”, “posisi”: “C”, “kondisi”: “AMF” },{ “金粉”: “P21”, “posisi”: “C”, “kondisi”: “AMF”}]}

我在我的视图中放了ajax函数。我可以在桌面上查看表吗?

function load(){
          $.ajax({
              url:"<?php echo base_url('c_dokter/odontogram');?>",
              type:"GET",
              data:{
                'id_odontogram': id_odontogram,
                "id_pasien": id_pasien,
                "gigi": gigi,
                "posisi": posisi,
                "kondisi": kondisi,
              },
              dataType:'json',
              success:function(data){
                console.log(data);
              },
              error:function(){
                alert('error ... ');
              }

            });


        }

2 个答案:

答案 0 :(得分:0)

<?php 
$selfaqCD=mysql_query("SELECT faq_cat_id FROM faq_cat WHERE faq_cat_status=1");
while($resfaqCD=mysql_fetch_array($selfaqCD)){?>
<div id="tab-1" class="tab-content current">
<?php $selfaq=mysql_query("SELECT * FROM faq WHERE faq_status=1 AND fk_faq_cat_id='".$resfaqCD['faq_cat_id']."'");
while($resfaq=mysql_fetch_array($selfaq)){?>
<h4>Q: <?php echo $resfaq['faq_ques']; ?></h4>
<?php echo $resfaq['faq_ans']; ?>
<?php } ?>
</div>
<?php } ?>

答案 1 :(得分:0)

首先解码json数据并使用类似这样的foreach ..

$arr = json_decode('[{"gigi":"P53","posisi":"C","kondisi":"amf"},{"gigi":"P61","posisi":"C","kondisi":"amf"},{"gigi":"P21","posisi":"C","kondisi":"amf"}]');

foreach($arr as $item) { 
    $uses = $item['gigi']; 
}