2013-10-21 99 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 –