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

div没有刷新,我在谷歌浏览器的控制台上收到一条错误消息: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>

最佳答案

您收到错误:


  jquery.js:5 GET 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');


您仍然可以从网址中删除这些index.php。

10-08 03:15