3

数秒ごとに更新されるテーブルがいくつかあるホームページがありました。

以下は、ビュー ファイル (inside_view.php) の jquery のコードです。

<script>
 $(document).ready(function() {
     $("#encontainer").load("inside/home_en");
   var refreshId = setInterval(function() {
      $("#encontainer").load('inside/home_en?randval='+ Math.random());
   }, 9000);
   $.ajaxSetup({ cache: false });
});

</script>
<div id="encontainer"></div>

これがコントローラーコードです(inside.php)

function index(){
  // Write to $title
  $this->template->write('title', 'Update to date data');
  $this->template->write_view('header', 'header_content', true);
  // Write to $content
  $this->template->write_view('content', 'inside_view', true);
  // Write to $sidebar
  $this->template->write_view('sidebar', 'user_side_menu');
  // Load and display the template
  $this->template->load();
}

function home_en(){
 //look latest enquirer data
 $data['enresults'] = $this->customer_model->get_cp_list(5);
 $this->load->view('ajax_home_en',$data);
}

ここに(ajax_home_en.php)コードがあります

<link type="text/css" rel="stylesheet" href="http://bravonet.my/tombocrm/assets/css/table.css" />  
<?php if($enresults->num_rows() == 0){
    echo 'No data result, please insert one';
}else{
?>
 <table width="100%">
    <tr>
        <th>CP code</th>
        <th>Code</th>
        <th>Name</th>
    </tr>
    <?php foreach($enresults->result() as $row){
         echo  '<tr class="tr'. alternator('1', '2'). '">';
        ?>
        <td align="center"><?php echo $row->cp_code?></td>
        <td align="center"><?php echo $row->en_code?></td>
        <td align="center"><?php echo $row->name?></td>
        <td align="center"><?php echo anchor('customers/patient_update_view/'.$row->eid,'Edit');?></td>
        <td align="center"><?php echo anchor('customers/cp_details_view/'.$row->cpid,'View');?></td>
    </tr>
    <?php }?>
</table>
<?php 
echo anchor('customers','View all data');
} ?>

この URL http://mysite.com/insideでこのページを表示しようとすると、すべて問題あり ません

しかし、一度この URL http://mysite.com/inside/またはhttp://mysite.com/inside/indexを入力すると

<div id="encontainer"></div>

home_en() ビューの代わりに inside() ビューを表示します。n を指定すると、ボックス内のページが継続的に更新されます (IE が応答しなくなります)。

URL に "/" または /index を追加するとこのようなバグが発生する理由がわかりません。JavaScript の表示エラーですか?

高度なthx!

4

1 に答える 1

4

相対リンクに問題がある可能性があります。試してください:

$(function() {
     $("#encontainer").load("/inside/home_en");
   var refreshId = setInterval(function() {
      $("#encontainer").load('/inside/home_en?randval='+ Math.random());
   }, 9000);
   $.ajaxSetup({ cache: false });
});
于 2011-06-30T08:52:12.970 に答える