如何获取PHP回显到jQuery弹出警报

时间:2019-02-11 10:50:19

标签: php jquery

我在电子邮件验证代码下面。

  

使用URL:/my_web/back-end/email-verify.php?email=email@gmail.com&code=Vruxc9JQwZEKjbz3HbZ2KlGPX10mJneDmH67hILqFooXeJIQB9

经过验证后,如何才能使jquery在索引页上弹出 任何可能的方法来获取php echo值到jquery?

    if(isset($_GET['email']) && !empty($_GET['email']) AND isset($_GET['code']) && !empty($_GET['code'])){
    // Verify data
    $email = mysqli_escape_string($conn,$_GET['email']); // Set email variable
    $hash = mysqli_escape_string($conn,$_GET['code']); // Set hash variable

    $sql="SELECT * FROM users WHERE user_email='".$email."' AND hashid='".$hash."' AND valied_user_1='0'";

   $search = mysqli_query($conn,$sql);


    if(mysqli_num_rows($search) > 0){
        // We have a match, activate the account
        $update="UPDATE users SET valied_user_1='1' WHERE user_email='".$email."' AND hashid='".$hash."' AND valied_user_1='0'";
        mysqli_query($conn,$update);
        echo"success";
        }else{
       ///other echo
    }
  

JQUERY函数

$(document).ready(function(){
    if(success){
                            $('#alert').addClass('alert-success alert-dismissible fade show');
                            $('#alertText').html('Your account has been activated, you can now login.');
                            $('.modal4').show();
                        }
});
  

html modal4

<div class="modal4">
            <div class="container alert-popup">
                <div id="alert" class="alert">
                    <button type="button" id="alertcloss" class="close">&times;</button>
                    <p id="alertText"></p>
                </div>
            </div>
        </div>

1 个答案:

答案 0 :(得分:1)

使用email_validation.php参数将index.php重定向到GET页面。 http://sample.com/index.php?success=1和在index.php页面上都喜欢

<div class="modal4">
            <div class="container alert-popup">
                <div id="alert" class="alert">
                    <button type="button" id="alertcloss" class="close">&times;</button>
                    <p id="alertText"></p>
                </div>
            </div>
        </div>


<?php 
if(isset($_GET['success']) {
?>
$(document).ready(function(){
                            $('#alert').addClass('alert-success alert-dismissible fade show');
                            $('#alertText').html('Your account has been activated, you can now login.');
                            $('.modal4').show();
});
<?php
}
?>