在codeigniter错误中使用jquery加载页面内容(load page content using jquery in codeigniter error)

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

下面是视图文件中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>

这是控制器代码(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()视图而不是home_en()视图。 n将在框中连续刷新页面(并使我的IE停止响应)。

我不明白为什么在URL中添加“/”或/索引会导致这样的错误,我的javascript出现错误?

thx在先进!

I had a home page which have a few tables that refresh itself every few sec.

Below is the code for the jquery in view file (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>

and here is the controller code (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); }

here is the (ajax_home_en.php) code

<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'); } ?>

Everything is fine when i try to view this page with this url http://mysite.com/inside

but once i type this url http://mysite.com/inside/ or this http://mysite.com/inside/index

the

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

show inside() view instead of home_en() view. n will have continuous page refreshing in the box (and makes my IE stop responding).

I don't understand why adding a "/" or /index in the URL will cause such bug, is my javascript appear error?

thx in advanced!

最满意答案

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

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

It might be an issue with relative links, try:

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

更多推荐