在codeigniter中使用jquery加载页面内容错误
我有一个主页,其中有一些表格每隔几秒就会刷新一次。
下面是视图文件(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
但是一旦我输入这个网址 http://mysite.com/inside/ 或此 http://mysite.com/inside/index
显示
<div id="encontainer"></div>
inside() 视图而不是 home_en() 视图。 n 框中会有连续的页面刷新(并使我的 IE 停止响应)。
我不明白为什么在URL中添加“/”或/index会导致这样的错误,是我的javascript出现错误吗?
提前谢谢!
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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
可能是相对链接的问题,请尝试:
It might be an issue with relative links, try: