kross
kross

Reputation: 475

Auto refreshing div in Code Igniter

I'm having some problems with auto refreshing my div, using code igniter framework. What I'm trying to do in the code below is to auto refresh the particular div id="lot_info" every 1 second.

The div is not refreshing and I am getting an error at google chrome's console saying: jquery.js:5 GET http://mywebsite/Home/display_lot_table 404 (Not Found)

Controller:

public function index()
{
    $data['title'] = 'Test System';

    $view = 'view';

    $this->load->view('templates/normal_header', $data);
    $this->load_lot_table($view);
    $this->load->view('templates/legend_footer', $data);
}

public function load_lot_table($type)
{
    $config = array();
    $config['base_url'] = base_url()."index.php/Home/index";
    $config['total_rows'] = $this->home_model->record_count();
    $config['per_page'] = 10;
    $config['uri_segment'] = 3;
    $config['next_link'] = 'Next';
    $config['prev_link'] = 'Previous';

    $this->pagination->initialize($config);

    $page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
    $results = $this->home_model->fetch_lots($config['per_page'], $page);

    $data['disp_rows'] = $results;
    $data['links'] = $this->pagination->create_links();

    if($type == 'view')
    {
        return $this->load->view('home/index', $data);
    }
    elseif($type == 'refresh')
    {
        return $this->load->view('home/index', $data, true);
    }
}

public function display_lot_table()
{
    $refresh = 'refresh';
    $this->load_lot_table($refresh);
}

View:

<script>
$(document).ready(function()
{
    refresh();
});

function refresh()
{
    setTimeout(function()
    {
        $('#lot_info').load('<?php echo base_url();?>Home/display_lot_table');
        refresh();
    }, 1000);
}
</script>

<div id="lot_info" class="container">
    <table class="table table-responsive table-condensed table-bordered dispo-table">
        <tr>
            <th rowspan="2">AStatus</th>
            <th rowspan="2">A</th>
            <th rowspan="2">B</th>
            <th rowspan="2">C</th>
            <th rowspan="2">D</th>
            <th rowspan="2">E</th>
            <th rowspan="2">F</th>
            <th colspan="3" scope"col">G</th>
            <th rowspan="2">H</th>
        </tr>
        <tr>
            <th>I</th>
            <th>J</th>
            <th>K</th>
        </tr>


        <?php foreach($disp_rows as $row):?>
        <tr>
            <td><?php echo $row->Astatus;?></td>
            <td align="center"><?php echo $row->B;?></td>
            <td align="center"><?php echo $row->C;?></td>
            <td align="center"><?php echo $row->D;?></td>
            <td align="center"><?php echo $row->E;?></td>
            <td align="center"><?php echo $row->F;?></td>
            <td align="center"><?php echo $row->G;?></td>
            <td><?php echo $row->H;?></td>
            <td align="center"><?php echo $row->I;?></td>
            <td align="center">-</td>
            <td align="center"><?php echo $row->J;?></td>
        </tr>
        <?php endforeach?>
    </table>
</div>

Upvotes: 1

Views: 4498

Answers (1)

Norlihazmey Ghazali
Norlihazmey Ghazali

Reputation: 9060

You received error :

jquery.js:5 GET http://mywebsite/Home/display_lot_table 404 (Not Found)

Seems like the path url is not correct. Look closely, is that correct? cause i see you defined in controller method having code like $config['base_url'] = base_url()."index.php/Home/index";. Completely different with the code defined in jquery load as $('#lot_info').load('<?php echo base_url();?>Home/display_lot_table');. So why not adding index.php like below code :

$('#lot_info').load('<?php echo base_url();?>index.php/Home/display_lot_table');

You can remove those index.php from url anyway.

Upvotes: 2

Related Questions