栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

更新数据库后如何刷新页面?

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

更新数据库后如何刷新页面?

这就是我最近使用jQuery实现解决方案的方式。

每当发生 重大 更新时,PHP都会在数据库中增加一个字段。

<?php//  Call this function when data changesfunction update_clients(){    mysql_query( "UPDATE pageGen SET id = id + 1 LIMIT 1" );}//  Call this function to get the ID to pass to Javascriptfunction get_update(){    $result = mysql_query( "SELECT id FROM pageGen LIMIT 1" );    $update = mysql_result( $result, 0, 'id' );    return $update;}?>

最初加载页面时,使用数据库中的数字填充Javascript变量:

<script type="text/javascript">var pageGenID = 25218603  //  generated by PHPvar processUpdate = function( response ) {    if ( pageGenID < response )     {        replace_current_data_with_new_via_ajax();        pageGenID = response;    }}//  Compare our Page Generate ID against that of the servervar checkUpdates = function(){    serverPoll = setInterval( function()    {        $.get('script_to_return_latest_pageGenID.php',{ lastupdate: 1 },processUpdate, 'html');    }, 10000 )};//  Check for updates every 10 seconds$( document ).ready( checkUpdates );</script>


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/443123.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号