为了账号安全,请及时绑定邮箱和手机立即绑定

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

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

PHP
慕容708150 2021-06-02 16:33:07
我正在尝试制作一个页面来验证用户,一旦他们得到验证,它应该会自动显示新内容。我已经尝试过:<?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 中验证后自动显示新内容,或者一旦用户通过验证,网站会重新加载但只有一次。
查看完整描述

2 回答

?
慕尼黑5688855

TA贡献1848条经验 获得超2个赞

问题是您刷新页面,而不是使用 ajax 获取内容。

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

当用户验证==真时,浏览器刷新,下次用户验证==真,当然,网站不断刷新。

因此,如果 $user 已验证,您应该触发 ajax 以获取新内容。


查看完整回答
反对 回复 2021-06-04
?
皈依舞

TA贡献1851条经验 获得超3个赞

我可以通过添加 JavaScript 来解决这个问题 document.location.reload(true)


$('.verify-account').click(function() {

    $(this).prepend('<i style="margin-top:5px;margin-left:5px" class="fa fa fa-spinner fa-spin"></i> ');

    $.post('verify', function(data) {

        if (data.status == 'success') {

            $('.accountver').html('<strong class="text-success"><i class="fa fa-check"></i> Verified</strong>');

            $('.verify-account').html('<p1>Verified</p1>');

            $('.verify-account').prop('disabled', true);

            $('.verification').empty();

            document.location.reload(true)

        }

        $('.verify-account').find('i').remove();

        showAlert(data.status, data.message);

    }).fail(function(response) {

        $('.verify-account').find('i').remove();

        showAlert('error', 'There was a problem while perform this action. '+ response.responseText);

    });

});


查看完整回答
反对 回复 2021-06-04
  • 2 回答
  • 0 关注
  • 180 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信