将json数据放在table / div中

时间:2013-10-21 06:11:42

标签: codeigniter jquery

这是我的代码:

<script>
$(document).ready(function(){
setInterval(function(){
    $.ajax({
      type: 'get',
      url: base_url+'main/activity_window',
      dataType: 'json',
      success: function(html) {
              //don't know what the code here :(
      }          
    });
},30000);
});
</script>

这是我控制器内的代码:

function activity_window(){
    $this->load->model('core_m');
    $core_m = new Core_m;
    $t = $core_m->get_waybill_created();
    foreach($t as $result){
        echo json_encode(array('name'=>$result['waybillno']));
    }
}

这是我的div / table:

<div id="put_data_here"></div>
<table id="put_data_here"></table>

这是控制器的结果:

{ “名称”: “MAIN-0056-00000006”} { “名称”: “MAIN-0056-00000005”} { “名称”: “MAIN-0056-00000004”} { “名称”:“MAIN- 0056-00000003 “} {” 名称 “:” MAIN-0056-00000002 “} {” 名称 “:” MAIN-0056-00000001" }

如何将数据放在div或table中,如下所示:

New Waybill Entry MAIN-0056-00000006
New Waybill Entry MAIN-0056-00000005
New Waybill Entry MAIN-0056-00000004
New Waybill Entry MAIN-0056-00000003
New Waybill Entry MAIN-0056-00000002
New Waybill Entry MAIN-0056-00000001

请帮帮我..先谢谢你先生..

2 个答案:

答案 0 :(得分:0)

为什么不使用jQuery?

function load_page (option) {

     $('#put_data_here').load('something.php?option='+option).fadeIn(300);

}

答案 1 :(得分:0)

在你的成功功能中:

  success: function(html) {
          //don't know what the code here :(
          $("#put_data_here").html(html); //If you have jquery added
          document.getElementById("put_data_here").innerHTML = html; // Javascript solution
  }  

如果你想循环遍历json数组,那么你应该在添加到html之前这样做。