在数据库中更改用户数据后如何使用php刷新页面?

我正在尝试制作一个页面来验证用户,一旦他们得到验证,它应该会自动显示新内容。

我已经尝试过:

<?php if ($user[ 'verified']) echo '<META HTTP-EQUIV="Refresh" Content="0; URL='.$location.'">'; ?>

但问题在于,如果用户经过验证,则该站点会不断刷新。

<div class="notverified" <?php if ($user[ 'verified']) echo 'style="display:contents;"'; ?>>   
<span>You are verified (example)</span>
</div>

我希望在用户在 db 中验证后自动显示新内容,或者一旦用户通过验证,网站会重新加载但只有一次。


慕容708150
浏览 181回答 2
2回答

慕尼黑5688855

问题是您刷新页面,而不是使用 ajax 获取内容。<?php&nbsp;if&nbsp;($user[&nbsp;'verified'])&nbsp;echo&nbsp;'<META&nbsp;HTTP-EQUIV="Refresh"&nbsp;Content="0;&nbsp;URL='.$location.'">';&nbsp;?>当用户验证==真时,浏览器刷新,下次用户验证==真,当然,网站不断刷新。因此,如果 $user 已验证,您应该触发 ajax 以获取新内容。

皈依舞

我可以通过添加 JavaScript 来解决这个问题 document.location.reload(true)$('.verify-account').click(function() {&nbsp; &nbsp; $(this).prepend('<i style="margin-top:5px;margin-left:5px" class="fa fa fa-spinner fa-spin"></i> ');&nbsp; &nbsp; $.post('verify', function(data) {&nbsp; &nbsp; &nbsp; &nbsp; if (data.status == 'success') {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $('.accountver').html('<strong class="text-success"><i class="fa fa-check"></i> Verified</strong>');&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $('.verify-account').html('<p1>Verified</p1>');&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $('.verify-account').prop('disabled', true);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $('.verification').empty();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; document.location.reload(true)&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; $('.verify-account').find('i').remove();&nbsp; &nbsp; &nbsp; &nbsp; showAlert(data.status, data.message);&nbsp; &nbsp; }).fail(function(response) {&nbsp; &nbsp; &nbsp; &nbsp; $('.verify-account').find('i').remove();&nbsp; &nbsp; &nbsp; &nbsp; showAlert('error', 'There was a problem while perform this action. '+ response.responseText);&nbsp; &nbsp; });});
打开App,查看更多内容
随时随地看视频慕课网APP