3

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!

1 Answer 1

4

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 });
});
Sign up to request clarification or add additional context in comments.

1 Comment

THX DUDE! $("#encontainer").load("/inside/home_en"); $("#encontainer").load('/inside/home_en?randval='+ Math.random()); is not working but i change the slash to <?php base_url()?> and everything turn fine.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.