代码点火器中自动刷新div

时间:2015-09-15 01:57:15

标签: javascript php jquery codeigniter model-view-controller

我在使用代码点火器框架自动刷新我的div时遇到了一些问题。我在下面的代码中尝试做的是每1秒自动刷新特定的div id="lot_info"

div没有令人耳目一新,我在google chrome的控制台上收到错误消息:jquery.js:5 GET http://mywebsite/Home/display_lot_table 404 (Not Found)

控制器:

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

查看:

<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>

1 个答案:

答案 0 :(得分:2)

您收到了错误:

  

jquery.js:5获取http://mywebsite/Home/display_lot_table 404(未找到)

似乎路径网址不正确。仔细看,这是对的吗?因为我看到你在控制器方法中定义了像$config['base_url'] = base_url()."index.php/Home/index";这样的代码。与jquery加载中定义的代码$('#lot_info').load('<?php echo base_url();?>Home/display_lot_table');完全不同。那么为什么不添加index.php如下代码:

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

无论如何,你可以从url中删除那些index.php。