mysql中怎么刷新数据库_更新数据库后如何刷新页面?

小编典典

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

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

// Call this function when data changes

function update_clients()

{

mysql_query( "UPDATE pageGen SET id = id + 1 LIMIT 1" );

}

// Call this function to get the ID to pass to JavaScript

function get_update()

{

$result = mysql_query( "SELECT id FROM pageGen LIMIT 1" );

$update = mysql_result( $result, 0, 'id' );

return $update;

}

?>

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

var pageGenID = 25218603 // generated by PHP

var processUpdate = function( response )

{

if ( pageGenID < response )

{

replace_current_data_with_new_via_ajax();

pageGenID = response;

}

}

// Compare our Page Generate ID against that of the server

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

2020-05-29

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值