开发者

load page content using jquery in codeigniter error

开发者 https://www.devze.com 2023-03-16 04:45 出处:网络
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)

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->templat开发者_如何学JAVAe->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!


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 });
});
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号