我有一个主页,其中有几张表格,每隔几秒就会刷新一次。

下面是 View 文件中 jquery 的代码 (inside_view.php)

<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>

这是 Controller 代码(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');
} ?>

当我尝试使用此网址查看此页面时一切正常
http://mysite.com/inside

但是一旦我输入这个网址
http://mysite.com/inside/ 或这个 http://mysite.com/inside/index


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

显示 inside() View 而不是 home_en() View 。 n 将在框中连续刷新页面(并使我的 IE 停止响应)。

我不明白为什么在 URL 中添加“/”或/index 会导致此类错误,是我的 javascript 出现错误吗?

thx 先进!

最佳答案

可能是相对链接的问题,请尝试:

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

关于javascript - 在 codeigniter 错误中使用 jquery 加载页面内容,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/6532224/

10-12 00:20
查看更多