2011-06-30 31 views
3

我有一個主頁有幾張表,每隔幾秒刷新一次。使用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'); 
} ?> 

一切都很好,當我嘗試使用這個網址查看此頁http://mysite.com/inside

但一旦i型此URL http://mysite.com/inside/或該http://mysite.com/inside/index

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

顯示()內視圖,而不是home_en()圖。 n將在連續頁面刷新框中(並使我的IE停止響應)。

我不明白爲什麼在URL中添加「/」或/ index會導致這樣的錯誤,是我的javascript出現錯誤?

thx in advanced!

回答

4

這可能是相對鏈接的問題,請嘗試:

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

THX DUDE! (「#encontainer」)。load(「/ inside/home_en」); (「#encontainer」)。load('/ inside/home_en?randval ='+ Math.random()); 無法正常工作,但我將斜槓更改爲<?php base_url()?>,並且一切正常。 –