2013-10-21 43 views
0

这里是我的代码:认沽JSON数据

<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 /表:

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

这是控制器的结果:

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

如何把数据股利或表像这里面:

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 

请帮助我..先谢谢您先生..

回答

0

为什么不使用jQuery?

function load_page (option) { 

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

} 
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之前。

+0

是的,但它会显示如下:{“name”:“MAIN-0056-00000006”} {“name”:“MAIN-0056-00000005”} {“name”:“MAIN-0056-000 00004 “} {”name“:”MAIN-0056-00000003“} {”name“:”MAIN-0056-00000002“} {”name“:”MAIN-00 56-00000001“}我想要做的是,它将显示如下所示:新运单条目MAIN-0056-00000006
新运单条目MAIN-0056-00000005 –