2013-03-17 34 views
2

我想設置一個方法,讓我的頁面上的兩個表自動更新或者如果正確的話我錯了「異步」。我還需要第二次更新。我也使用CodeIgnighter MVC框架,至於我的表我正在使用DataTables。我的Jquery去如下:Jquery使用CodeIgniter的Ajax調用

<script> 
     function updatewaiting(){ 
     $('.display').load('https://www.finaidtest.com/index.php/studentqueue_controller/data'); 
     } 
     setInterval("updatewaiting()", 1000); 

    </script> 

我的表如下所示:

<table id='waiting' class='display'> 
     <thead> 
     <tr> 
      <th>ID</th> 
      <th>A Number</th> 
      <th>First Name</th> 
      <th>Last Name</th> 
      <th>Time Waiting</th> 
      <th>Reason for visit</th> 
      <th>Comments</th> 
      <th>Aid Year</th> 
      <th>Staff Comments</th> 
      <th>Options</th> 
     </tr> 
     </thead> 
     <tbody> 

     <?php 
     $options = array("" => "", 'start' => 'Start Session', 'stop' => 'Student Not Present', 'abandon' => 'End Session',); 
     foreach ($waiting as $row) { 
      ?> 
      <tr> 
       <td><?php echo htmlspecialchars($row['id'], ENT_QUOTES, 'UTF-8'); ?></td> 
       <td><?php echo anchor('studentqueue_controller/history/' . urlencode($row['anum']) . '', htmlspecialchars($row['anum'], ENT_QUOTES, 'UTF-8'), 'target="_blank"'); ?></td> 
       <td><?php echo htmlspecialchars($row['first'], ENT_QUOTES, 'UTF-8'); ?></td> 
       <td><?php echo htmlspecialchars($row['last'], ENT_QUOTES, 'UTF-8'); ?></td> 
       <td><?php echo htmlspecialchars($row['SECOND'], ENT_QUOTES, 'UTF-8'); ?></td> 
       <td><?php echo htmlspecialchars($row['reason'], ENT_QUOTES, 'UTF-8'); ?></td> 
       <td><?php echo htmlspecialchars($row['studentcomments'], ENT_QUOTES, 'UTF-8'); ?></td> 
       <td><?php echo htmlspecialchars($row['aidyear'], ENT_QUOTES, 'UTF-8'); ?></td> 
       <td><?php echo htmlspecialchars($row['counselorcomments'], ENT_QUOTES, 'UTF-8'); ?></td> 
       <td> 
       <?php echo form_open('studentqueue_controller/counselorscreen/' . urlencode($row['id']) . ''); ?> 
       <?php echo form_dropdown('options', $options, ""); ?> 
       <?php echo form_submit('submit', 'Submit'); ?> 
       <?php echo form_close(); ?> 
       </td> 
      </tr> 

      <?php } 
     ?> 
     </tbody> 
    </table> 

<table id='beingseen' class='display'> 
     <thead> 
     <tr> 
      <th>ID</th> 
      <th>A Number</th> 
      <th>First Name</th> 
      <th>Last Name</th> 
      <th>Sign In Time</th> 
      <th>Staff Member</th> 
      <th>Start Time</th> 
      <th>Options</th> 
     </tr> 
     </thead> 
     <tbody> 
     <?php $options1 = array("" => "", 'continue' => 'Continue Session', 'terminate' => 'Terminate Session',); 
     foreach ($beingseen as $row1) { 
      ?> 
      <tr> 
       <td><?php echo htmlspecialchars($row1['id'], ENT_QUOTES, 'UTF-8'); ?></td> 
       <td><?php echo htmlspecialchars($row1['anum'], ENT_QUOTES, 'UTF-8'); ?></td> 
       <td><?php echo htmlspecialchars($row1['first'], ENT_QUOTES, 'UTF-8'); ?></td> 
       <td><?php echo htmlspecialchars($row1['last'], ENT_QUOTES, 'UTF-8'); ?></td> 
       <td><?php echo htmlspecialchars($row1['signintime'], ENT_QUOTES, 'UTF-8'); ?></td> 
       <td><?php echo htmlspecialchars($row1['fname'], ENT_QUOTES, 'UTF-8'); ?></td> 
       <td><?php echo htmlspecialchars($row1['starttime'], ENT_QUOTES, 'UTF-8'); ?></td> 
       <td> 
       <?php echo form_open('studentqueue_controller/counselorscreen/' . urlencode($row1['id']) . ''); ?> 
       <?php echo form_dropdown('options', $options1, ""); ?> 
       <?php echo form_submit('submit', 'Submit'); ?> 
    <?php echo form_close(); ?> 
       </td> 
       </td> 
      </tr> 
<?php } ?> 


     </tbody> 
    </table> 

jQuery的功能是在我的數據調用()在我的控制方法和所有做的是查詢數據庫:

function data(){ 
    $this->load->model('queue_model'); 

    $data['waiting'] = $this->queue_model->waiting(); 
    $data['beingseen'] = $this->queue_model->beingseen(); 
    } 

我很困惑,爲什麼當我查看我的網絡選項卡時,我看到ajax調用,但在網絡選項卡中看不到響應。

只是一個向上日期:

Array ([waiting] => Array ([0] => Array ([id] => 176 [0] => 176 [anum] => A00163047 [1] => A00163047 [first] => rix [2] => rix [last] => aja [3] => aja [SECOND] => 62:47:39 [4] => 62:47:39 [reason] => Award Status [5] => Award Status [studentcomments] => [6] => [aidyear] => 13-14 [7] => 13-14 [counselorcomments] => [8] =>) [1] => Array ([id] => 179 [0] => 179 [anum] => A00163047 [1] => A00163047 [first] => rix [2] => rix [last] => aja [3] => aja [SECOND] => 00:22:29 [4] => 00:22:29 [reason] => Award Status [5] => Award Status [studentcomments] => [6] => [aidyear] => 13-14 [7] => 13-14 [counselorcomments] => [8] =>) [2] => Array ([id] => 178 [0] => 178 [anum] => A12345678 [1] => A12345678 [first] => ririri [2] => ririri [last] => ririir [3] => ririir [SECOND] => 00:24:21 [4] => 00:24:21 [reason] => Award Status [5] => Award Status [studentcomments] => [6] => [aidyear] => 13-14 [7] => 13-14 [counselorcomments] => [8] =>) [3] => Array ([id] => 177 [0] => 177 [anum] => A99999999 [1] => A99999999 [first] => rux [2] => rux [last] => ajaj [3] => ajaj [SECOND] => 00:29:20 [4] => 00:29:20 [reason] => Award Status [5] => Award Status [studentcomments] => [6] => [aidyear] => 13-14 [7] => 13-14 [counselorcomments] => [8] =>)) [beingseen] =>) 

我其實數據功能是將數據返回到控制器。我只是對我的數據做了print_r。但是返回的數據進行陣列被置於表的本身,

+1

你的數據函數沒有返回任何東西。 – 2013-03-17 14:31:33

+0

更新了我的文章 – Joe 2013-03-17 14:37:48

+0

是的,它返回到控制器,但控制器沒有將其返回到視圖。沒有返回,沒有打印,視圖永遠不會看到這些數據。 – 2013-03-17 14:43:33

回答

0

在你的情況,你應該加載一個視圖,並使用load()打印在javascript,所以用:

function data(){ 
     $this->load->model('queue_model'); 

     $data['waiting'] = $this->queue_model->waiting(); 
     $data['beingseen'] = $this->queue_model->beingseen(); 

     echo $this->load->view('myview',$data,true); 
    } 

,你的觀點將被輸出你在哪裏用$(_element).load();

specifiying只是要確定你理解的load()jQuery的方法:

當你做$('div#element').load('myfile.php');outputtting the returning data from myfile.phpinto the <div id="element"></div> html元素

+0

更新了我的文章 – Joe 2013-03-17 14:37:03

+0

@Joe更新了答案 – sbaaaang 2013-03-17 14:40:57

+0

仍然在網絡選項卡中顯示,以及我如何處理json_encoded數據?只是把它扔在視圖? – Joe 2013-03-17 14:46:11