Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 每次在db表中插入记录时更新CakePhp视图_Javascript_Jquery_Cakephp_Websocket_Phpwebsocket - Fatal编程技术网

Javascript 每次在db表中插入记录时更新CakePhp视图

Javascript 每次在db表中插入记录时更新CakePhp视图,javascript,jquery,cakephp,websocket,phpwebsocket,Javascript,Jquery,Cakephp,Websocket,Phpwebsocket,我正在制作一个应用程序,可以通过浏览器远程查看记录和报告。我使用cakePHP使应用程序及其工作正常,但我有一个小问题,因为应用程序不做任何插入,只是读取数据,我希望当用户打开视图并在表上插入记录时,它应该更新所有打开的客户端,而不是用户刷新页面以获得新记录。 是否有一个真正有效的cakePHP websocket插件? 我们的Web主机不允许安装程序或添加apache模块,因此nodejs或类似的解决方案在这里不适用 我正在寻找一个纯粹的php和javascript实现,其中 只需将您的应用程

我正在制作一个应用程序,可以通过浏览器远程查看记录和报告。我使用cakePHP使应用程序及其工作正常,但我有一个小问题,因为应用程序不做任何插入,只是读取数据,我希望当用户打开视图并在表上插入记录时,它应该更新所有打开的客户端,而不是用户刷新页面以获得新记录。 是否有一个真正有效的cakePHP websocket插件? 我们的Web主机不允许安装程序或添加apache模块,因此nodejs或类似的解决方案在这里不适用

我正在寻找一个纯粹的php和javascript实现,其中 只需将您的应用程序文件上载到Web服务器和所有内容 跑。你不必在apache上运行、安装附加程序或进行任何配置或诸如此类的操作。。。上传文件后

下面是我的一个控制器(BooksController.php)中的一个函数,它将数据检索到视图中

public function list_books()
  {
    $this->Books->recursive = 0;
    $this->paginate = array('order' => array('Serial_No' => 'DESC'));
    $this->set('All_Books', $this->paginate());
  }
这是我的一个视图(list_books.ctp),它在分页的表中显示数据

<div class="row-fluid">

    <div class="span12">
        <?php echo $this->Session->flash() ?>   
        <h4><?php echo __('All Books') ?></h4>
        <hr>               
                    <table class="table table-bordered">
            <thead>
                <tr>    <th><?php echo __('Serial No') ?></th>
                    <th><?php echo __('Title') ?></th>
                                        <th><?php echo __('Author') ?></th>
                                        <th><?php echo __('Publisher') ?></th>
                                        <th><?php echo __('Category') ?></th>
                                        <th><?php echo __('Section') ?></th>
                                        <th><?php echo __('Available') ?></th>
                </tr>
            </thead>
            <tbody>
                <?php foreach( $All_Books as $book ){ ?>
                <tr>
                    <td><?php echo $this->Html->link(__($book['Book']['Serial_No']),'/books/view/'.$book['Book']['Serial_No']) ?></td>                                         
                                        <td><?php echo $book['Book']['Title'] ?></td>
                                        <td><?php echo $book['Book']['Author'] ?></td>
                                        <td><?php echo $book['Book']['Publisher'] ?></td>
                                        <td><?php echo $book['Book']['Category'] ?></td>
                                        <td><?php echo $book['Book']['Section'] ?></td>
                                        <td><?php echo $book['Book']['Available'] ?></td>
                </tr>
                <?php } ?>
            </tbody>
        </table>
                <?php echo $this->Paginator->prev('« Previous', null, null, array('class' => 'disabled'));            
echo $this->Paginator->numbers();
echo $this->Paginator->next('Next »', null, null, array('class' => 'disabled'));
echo $this->Paginator->counter(array(
    'format' => 'Page {:page} of {:pages}, showing {:current} records out of
             {:count} total, starting on record {:start}, ending on {:end}'
));
 ?>
    </div>

</div>


我可以在视图、控制器或模型上添加什么,以使视图自动更新?
这可以通过使用ajax实现吗?

您可以使用ajax轮询器,或者(HTML5)WebSocket(例如使用)进行推送通知。

您已经提到了,ajax。这是完成类似任务的最简单的方法,只需通过AJAX在后台进行检查,必要时重新加载页面,或者再次使用AJAX请求仅更新受影响的部分

当然,根据数据量的不同,您可以直接加载数据,而不是先检查更新

更新我误解了这个问题,如果插入/udpate是从外部来源进行的,而您在评论中没有直接控制,那么我唯一能想到的检查是否需要更新视图的选项就是检查
更新时间
(仅适用于MyISAM),用于更新可检查的自定义信息架构,或计算行数,但后者仅包括插入

所有方法都将在特定视图的控制器操作中获取比较值(更新时间或行计数),并将该值传递给视图,然后在AJAX调用中使用该值。AJAX调用调用一个控制器方法,将传递的值与当前时间/计数值进行比较,以确定是否需要更新

请注意,这些示例未经测试

信息模式 最简单的方法是检查
UPDATE\u TIME
信息模式,但是如上所述,这只适用于MyISAM表:

型号:

public function getUpdateTime()
{   
    $db = $this->getDataSource();
    
    $result = $db->fetchAll('
        SELECT
            UNIX_TIMESTAMP(UPDATE_TIME) AS update_time
        FROM
            information_schema.tables
        WHERE
            TABLE_SCHEMA = ?
            AND
            TABLE_NAME = ?',
            
        array
        (
            $db->config['database'],
            $this->table
        )
    );
    
    if(empty($result) || !isset($result[0][0]['update_time']))
    {
        return false;
    }
    
    return (int)$result[0][0]['update_time'];
}
public function list_books()
{
    $this->set('lastUpdate', $this->Books->getUpdateTime());
    
    $this->Books->recursive = 0;
    $this->paginate = array('order' => array('Serial_No' => 'DESC'));
    $this->set('All_Books', $this->paginate());
}

public function checkForUpdate($time)
{
    $updateNecessary = $this->Books->getUpdateTime() > (int)$time;
    return new CakeResponse(array('body' => json_encode($updateNecessary)));
}
<script>
jQuery(function($)
{
    var lastUpdate = <?php echo $lastUpdate; ?>;
    
    function checkForUpdate()
    {
        $.get('/books/checkForUpdate', {time: lastUpdate}, function(updateNecessary)
        {
            if(updateNecessary === true)
            {
                alert('update necessary');
                // now reload the page or use an additional AJAX request for updating the content
            }
            else
            {
                queueUpdateCheck();
            }
        },
        'json');
    }
    
    function queueUpdateCheck()
    {
        setTimeout(checkForUpdate, 5000);
    }
    
    queueUpdateCheck();
});
</script>
public function getUpdateTime()
{   
    $db = $this->getDataSource();
    
    $result = $db->fetchAll('
        SELECT
            UNIX_TIMESTAMP(update_time) AS update_time
        FROM
            `table_stats`
        WHERE
            `table_name` = ?',
            
        array
        (
            $this->table
        )
    );
    
    if(empty($result) || !isset($result[0][0]['update_time']))
    {
        return false;
    }
    
    return (int)$result[0][0]['update_time'];
}
public function list_books()
{
    $this->set('rowCount', $this->Books->find('count'));
    
    $this->Books->recursive = 0;
    $this->paginate = array('order' => array('Serial_No' => 'DESC'));
    $this->set('All_Books', $this->paginate());
}

public function checkForUpdate($rowCount)
{
    $updateNecessary = $this->Books->find('count') != (int)$rowCount;
    return new CakeResponse(array('body' => json_encode($updateNecessary)));
}
<script>
jQuery(function($)
{
    var rowCount = <?php echo $rowCount; ?>;
    
    function checkForUpdate()
    {
        $.get('/books/checkForUpdate', {rowCount: rowCount}, function(updateNecessary)
        {
            if(updateNecessary === true)
            {
                alert('update necessary');
                // now reload the page or use an additional AJAX request for updating the content
            }
            else
            {
                queueUpdateCheck();
            }
        },
        'json');
    }
    
    function queueUpdateCheck()
    {
        setTimeout(checkForUpdate, 5000);
    }
    
    queueUpdateCheck();
});
</script>
控制器:

public function getUpdateTime()
{   
    $db = $this->getDataSource();
    
    $result = $db->fetchAll('
        SELECT
            UNIX_TIMESTAMP(UPDATE_TIME) AS update_time
        FROM
            information_schema.tables
        WHERE
            TABLE_SCHEMA = ?
            AND
            TABLE_NAME = ?',
            
        array
        (
            $db->config['database'],
            $this->table
        )
    );
    
    if(empty($result) || !isset($result[0][0]['update_time']))
    {
        return false;
    }
    
    return (int)$result[0][0]['update_time'];
}
public function list_books()
{
    $this->set('lastUpdate', $this->Books->getUpdateTime());
    
    $this->Books->recursive = 0;
    $this->paginate = array('order' => array('Serial_No' => 'DESC'));
    $this->set('All_Books', $this->paginate());
}

public function checkForUpdate($time)
{
    $updateNecessary = $this->Books->getUpdateTime() > (int)$time;
    return new CakeResponse(array('body' => json_encode($updateNecessary)));
}
<script>
jQuery(function($)
{
    var lastUpdate = <?php echo $lastUpdate; ?>;
    
    function checkForUpdate()
    {
        $.get('/books/checkForUpdate', {time: lastUpdate}, function(updateNecessary)
        {
            if(updateNecessary === true)
            {
                alert('update necessary');
                // now reload the page or use an additional AJAX request for updating the content
            }
            else
            {
                queueUpdateCheck();
            }
        },
        'json');
    }
    
    function queueUpdateCheck()
    {
        setTimeout(checkForUpdate, 5000);
    }
    
    queueUpdateCheck();
});
</script>
public function getUpdateTime()
{   
    $db = $this->getDataSource();
    
    $result = $db->fetchAll('
        SELECT
            UNIX_TIMESTAMP(update_time) AS update_time
        FROM
            `table_stats`
        WHERE
            `table_name` = ?',
            
        array
        (
            $this->table
        )
    );
    
    if(empty($result) || !isset($result[0][0]['update_time']))
    {
        return false;
    }
    
    return (int)$result[0][0]['update_time'];
}
public function list_books()
{
    $this->set('rowCount', $this->Books->find('count'));
    
    $this->Books->recursive = 0;
    $this->paginate = array('order' => array('Serial_No' => 'DESC'));
    $this->set('All_Books', $this->paginate());
}

public function checkForUpdate($rowCount)
{
    $updateNecessary = $this->Books->find('count') != (int)$rowCount;
    return new CakeResponse(array('body' => json_encode($updateNecessary)));
}
<script>
jQuery(function($)
{
    var rowCount = <?php echo $rowCount; ?>;
    
    function checkForUpdate()
    {
        $.get('/books/checkForUpdate', {rowCount: rowCount}, function(updateNecessary)
        {
            if(updateNecessary === true)
            {
                alert('update necessary');
                // now reload the page or use an additional AJAX request for updating the content
            }
            else
            {
                queueUpdateCheck();
            }
        },
        'json');
    }
    
    function queueUpdateCheck()
    {
        setTimeout(checkForUpdate, 5000);
    }
    
    queueUpdateCheck();
});
</script>
查看:

public function getUpdateTime()
{   
    $db = $this->getDataSource();
    
    $result = $db->fetchAll('
        SELECT
            UNIX_TIMESTAMP(UPDATE_TIME) AS update_time
        FROM
            information_schema.tables
        WHERE
            TABLE_SCHEMA = ?
            AND
            TABLE_NAME = ?',
            
        array
        (
            $db->config['database'],
            $this->table
        )
    );
    
    if(empty($result) || !isset($result[0][0]['update_time']))
    {
        return false;
    }
    
    return (int)$result[0][0]['update_time'];
}
public function list_books()
{
    $this->set('lastUpdate', $this->Books->getUpdateTime());
    
    $this->Books->recursive = 0;
    $this->paginate = array('order' => array('Serial_No' => 'DESC'));
    $this->set('All_Books', $this->paginate());
}

public function checkForUpdate($time)
{
    $updateNecessary = $this->Books->getUpdateTime() > (int)$time;
    return new CakeResponse(array('body' => json_encode($updateNecessary)));
}
<script>
jQuery(function($)
{
    var lastUpdate = <?php echo $lastUpdate; ?>;
    
    function checkForUpdate()
    {
        $.get('/books/checkForUpdate', {time: lastUpdate}, function(updateNecessary)
        {
            if(updateNecessary === true)
            {
                alert('update necessary');
                // now reload the page or use an additional AJAX request for updating the content
            }
            else
            {
                queueUpdateCheck();
            }
        },
        'json');
    }
    
    function queueUpdateCheck()
    {
        setTimeout(checkForUpdate, 5000);
    }
    
    queueUpdateCheck();
});
</script>
public function getUpdateTime()
{   
    $db = $this->getDataSource();
    
    $result = $db->fetchAll('
        SELECT
            UNIX_TIMESTAMP(update_time) AS update_time
        FROM
            `table_stats`
        WHERE
            `table_name` = ?',
            
        array
        (
            $this->table
        )
    );
    
    if(empty($result) || !isset($result[0][0]['update_time']))
    {
        return false;
    }
    
    return (int)$result[0][0]['update_time'];
}
public function list_books()
{
    $this->set('rowCount', $this->Books->find('count'));
    
    $this->Books->recursive = 0;
    $this->paginate = array('order' => array('Serial_No' => 'DESC'));
    $this->set('All_Books', $this->paginate());
}

public function checkForUpdate($rowCount)
{
    $updateNecessary = $this->Books->find('count') != (int)$rowCount;
    return new CakeResponse(array('body' => json_encode($updateNecessary)));
}
<script>
jQuery(function($)
{
    var rowCount = <?php echo $rowCount; ?>;
    
    function checkForUpdate()
    {
        $.get('/books/checkForUpdate', {rowCount: rowCount}, function(updateNecessary)
        {
            if(updateNecessary === true)
            {
                alert('update necessary');
                // now reload the page or use an additional AJAX request for updating the content
            }
            else
            {
                queueUpdateCheck();
            }
        },
        'json');
    }
    
    function queueUpdateCheck()
    {
        setTimeout(checkForUpdate, 5000);
    }
    
    queueUpdateCheck();
});
</script>
触发器

CREATE TRIGGER `update_time_after_insert` AFTER INSERT ON `books`
    FOR EACH ROW 
        UPDATE `table_stats` SET `update_time` = NOW() WHERE `table_name` = 'books';

CREATE TRIGGER `update_time_after_update` AFTER UPDATE ON `books`
    FOR EACH ROW 
        UPDATE `table_stats` SET `update_time` = NOW() WHERE `table_name` = 'books';
型号:

public function getUpdateTime()
{   
    $db = $this->getDataSource();
    
    $result = $db->fetchAll('
        SELECT
            UNIX_TIMESTAMP(UPDATE_TIME) AS update_time
        FROM
            information_schema.tables
        WHERE
            TABLE_SCHEMA = ?
            AND
            TABLE_NAME = ?',
            
        array
        (
            $db->config['database'],
            $this->table
        )
    );
    
    if(empty($result) || !isset($result[0][0]['update_time']))
    {
        return false;
    }
    
    return (int)$result[0][0]['update_time'];
}
public function list_books()
{
    $this->set('lastUpdate', $this->Books->getUpdateTime());
    
    $this->Books->recursive = 0;
    $this->paginate = array('order' => array('Serial_No' => 'DESC'));
    $this->set('All_Books', $this->paginate());
}

public function checkForUpdate($time)
{
    $updateNecessary = $this->Books->getUpdateTime() > (int)$time;
    return new CakeResponse(array('body' => json_encode($updateNecessary)));
}
<script>
jQuery(function($)
{
    var lastUpdate = <?php echo $lastUpdate; ?>;
    
    function checkForUpdate()
    {
        $.get('/books/checkForUpdate', {time: lastUpdate}, function(updateNecessary)
        {
            if(updateNecessary === true)
            {
                alert('update necessary');
                // now reload the page or use an additional AJAX request for updating the content
            }
            else
            {
                queueUpdateCheck();
            }
        },
        'json');
    }
    
    function queueUpdateCheck()
    {
        setTimeout(checkForUpdate, 5000);
    }
    
    queueUpdateCheck();
});
</script>
public function getUpdateTime()
{   
    $db = $this->getDataSource();
    
    $result = $db->fetchAll('
        SELECT
            UNIX_TIMESTAMP(update_time) AS update_time
        FROM
            `table_stats`
        WHERE
            `table_name` = ?',
            
        array
        (
            $this->table
        )
    );
    
    if(empty($result) || !isset($result[0][0]['update_time']))
    {
        return false;
    }
    
    return (int)$result[0][0]['update_time'];
}
public function list_books()
{
    $this->set('rowCount', $this->Books->find('count'));
    
    $this->Books->recursive = 0;
    $this->paginate = array('order' => array('Serial_No' => 'DESC'));
    $this->set('All_Books', $this->paginate());
}

public function checkForUpdate($rowCount)
{
    $updateNecessary = $this->Books->find('count') != (int)$rowCount;
    return new CakeResponse(array('body' => json_encode($updateNecessary)));
}
<script>
jQuery(function($)
{
    var rowCount = <?php echo $rowCount; ?>;
    
    function checkForUpdate()
    {
        $.get('/books/checkForUpdate', {rowCount: rowCount}, function(updateNecessary)
        {
            if(updateNecessary === true)
            {
                alert('update necessary');
                // now reload the page or use an additional AJAX request for updating the content
            }
            else
            {
                queueUpdateCheck();
            }
        },
        'json');
    }
    
    function queueUpdateCheck()
    {
        setTimeout(checkForUpdate, 5000);
    }
    
    queueUpdateCheck();
});
</script>
控制器视图与上一示例中的相同


数行 现在最后一个选项是比较行数,这当然只适用于插入。在本例中,模型将保持不变

控制器:

public function getUpdateTime()
{   
    $db = $this->getDataSource();
    
    $result = $db->fetchAll('
        SELECT
            UNIX_TIMESTAMP(UPDATE_TIME) AS update_time
        FROM
            information_schema.tables
        WHERE
            TABLE_SCHEMA = ?
            AND
            TABLE_NAME = ?',
            
        array
        (
            $db->config['database'],
            $this->table
        )
    );
    
    if(empty($result) || !isset($result[0][0]['update_time']))
    {
        return false;
    }
    
    return (int)$result[0][0]['update_time'];
}
public function list_books()
{
    $this->set('lastUpdate', $this->Books->getUpdateTime());
    
    $this->Books->recursive = 0;
    $this->paginate = array('order' => array('Serial_No' => 'DESC'));
    $this->set('All_Books', $this->paginate());
}

public function checkForUpdate($time)
{
    $updateNecessary = $this->Books->getUpdateTime() > (int)$time;
    return new CakeResponse(array('body' => json_encode($updateNecessary)));
}
<script>
jQuery(function($)
{
    var lastUpdate = <?php echo $lastUpdate; ?>;
    
    function checkForUpdate()
    {
        $.get('/books/checkForUpdate', {time: lastUpdate}, function(updateNecessary)
        {
            if(updateNecessary === true)
            {
                alert('update necessary');
                // now reload the page or use an additional AJAX request for updating the content
            }
            else
            {
                queueUpdateCheck();
            }
        },
        'json');
    }
    
    function queueUpdateCheck()
    {
        setTimeout(checkForUpdate, 5000);
    }
    
    queueUpdateCheck();
});
</script>
public function getUpdateTime()
{   
    $db = $this->getDataSource();
    
    $result = $db->fetchAll('
        SELECT
            UNIX_TIMESTAMP(update_time) AS update_time
        FROM
            `table_stats`
        WHERE
            `table_name` = ?',
            
        array
        (
            $this->table
        )
    );
    
    if(empty($result) || !isset($result[0][0]['update_time']))
    {
        return false;
    }
    
    return (int)$result[0][0]['update_time'];
}
public function list_books()
{
    $this->set('rowCount', $this->Books->find('count'));
    
    $this->Books->recursive = 0;
    $this->paginate = array('order' => array('Serial_No' => 'DESC'));
    $this->set('All_Books', $this->paginate());
}

public function checkForUpdate($rowCount)
{
    $updateNecessary = $this->Books->find('count') != (int)$rowCount;
    return new CakeResponse(array('body' => json_encode($updateNecessary)));
}
<script>
jQuery(function($)
{
    var rowCount = <?php echo $rowCount; ?>;
    
    function checkForUpdate()
    {
        $.get('/books/checkForUpdate', {rowCount: rowCount}, function(updateNecessary)
        {
            if(updateNecessary === true)
            {
                alert('update necessary');
                // now reload the page or use an additional AJAX request for updating the content
            }
            else
            {
                queueUpdateCheck();
            }
        },
        'json');
    }
    
    function queueUpdateCheck()
    {
        setTimeout(checkForUpdate, 5000);
    }
    
    queueUpdateCheck();
});
</script>
查看:

public function getUpdateTime()
{   
    $db = $this->getDataSource();
    
    $result = $db->fetchAll('
        SELECT
            UNIX_TIMESTAMP(UPDATE_TIME) AS update_time
        FROM
            information_schema.tables
        WHERE
            TABLE_SCHEMA = ?
            AND
            TABLE_NAME = ?',
            
        array
        (
            $db->config['database'],
            $this->table
        )
    );
    
    if(empty($result) || !isset($result[0][0]['update_time']))
    {
        return false;
    }
    
    return (int)$result[0][0]['update_time'];
}
public function list_books()
{
    $this->set('lastUpdate', $this->Books->getUpdateTime());
    
    $this->Books->recursive = 0;
    $this->paginate = array('order' => array('Serial_No' => 'DESC'));
    $this->set('All_Books', $this->paginate());
}

public function checkForUpdate($time)
{
    $updateNecessary = $this->Books->getUpdateTime() > (int)$time;
    return new CakeResponse(array('body' => json_encode($updateNecessary)));
}
<script>
jQuery(function($)
{
    var lastUpdate = <?php echo $lastUpdate; ?>;
    
    function checkForUpdate()
    {
        $.get('/books/checkForUpdate', {time: lastUpdate}, function(updateNecessary)
        {
            if(updateNecessary === true)
            {
                alert('update necessary');
                // now reload the page or use an additional AJAX request for updating the content
            }
            else
            {
                queueUpdateCheck();
            }
        },
        'json');
    }
    
    function queueUpdateCheck()
    {
        setTimeout(checkForUpdate, 5000);
    }
    
    queueUpdateCheck();
});
</script>
public function getUpdateTime()
{   
    $db = $this->getDataSource();
    
    $result = $db->fetchAll('
        SELECT
            UNIX_TIMESTAMP(update_time) AS update_time
        FROM
            `table_stats`
        WHERE
            `table_name` = ?',
            
        array
        (
            $this->table
        )
    );
    
    if(empty($result) || !isset($result[0][0]['update_time']))
    {
        return false;
    }
    
    return (int)$result[0][0]['update_time'];
}
public function list_books()
{
    $this->set('rowCount', $this->Books->find('count'));
    
    $this->Books->recursive = 0;
    $this->paginate = array('order' => array('Serial_No' => 'DESC'));
    $this->set('All_Books', $this->paginate());
}

public function checkForUpdate($rowCount)
{
    $updateNecessary = $this->Books->find('count') != (int)$rowCount;
    return new CakeResponse(array('body' => json_encode($updateNecessary)));
}
<script>
jQuery(function($)
{
    var rowCount = <?php echo $rowCount; ?>;
    
    function checkForUpdate()
    {
        $.get('/books/checkForUpdate', {rowCount: rowCount}, function(updateNecessary)
        {
            if(updateNecessary === true)
            {
                alert('update necessary');
                // now reload the page or use an additional AJAX request for updating the content
            }
            else
            {
                queueUpdateCheck();
            }
        },
        'json');
    }
    
    function queueUpdateCheck()
    {
        setTimeout(checkForUpdate, 5000);
    }
    
    queueUpdateCheck();
});
</script>
查看

<script>
jQuery(function($)
{
    var lastUpdate = <?php echo $lastUpdate; ?>;

    function checkForUpdate()
    {
        $.get('/books/checkForUpdate', {time: lastUpdate}, function(response)
        {
            if(response.updateAvailable === true)
            {
                // the data is already available, so directly update the content
                $('#content').html(response.data);
            }
            
            queueUpdateCheck();
        },
        'json');
    }

    function queueUpdateCheck()
    {
        setTimeout(checkForUpdate, 5000);
    }

    queueUpdateCheck();
});
</script>

jQuery(函数($)
{
var lastUpdate=;
函数checkForUpdate()
{
$.get('/books/checkForUpdate',{time:lastUpdate},函数(响应)
{
if(response.updateAvailable===true)
{
//数据已经可用,因此直接更新内容
$('#content').html(response.data);
}
queueUpdateCheck();
},
“json”);
}
函数queueUpdateCheck()
{
设置超时(checkForUpdate,5000);
}
queueUpdateCheck();
});

我没有对cakephp(web应用程序)进行任何更新或插入,所以这仍然有效吗?“Cache::write('model_last_update_books',time());”对不起,我误解了你的问题。不,在这种情况下,这将不起作用,因为
afterSave
回调仅在模型保存时触发。您是否对进行实际插入/更新的应用程序有任何影响?例如,您是否可以让它插入/更新其他数据,或者如果它运行在同一台服务器上,是否可以将数据写入文件系统?如果没有,插入/更新是否包括创建/修改日期?我无法访问该系统,它是一个桌面应用程序不同用户的pc和我们应用程序服务器上的服务器,但它不会在所有表上保存修改日期和时间,我们需要的大多数数据都在没有修改日期和时间的表中我明白了。。。您正在使用哪个DBMS(版本和存储引擎)?这是一个固定的需求,还是您希望支持不同的DBMS?我们使用Mysql以及innodb和myisam表。我们无法更改,因为桌面系统无法支持其他dbms。