【问题标题】:jquery .post can't pass the value into php for checkingjquery .post 无法将值传递给 php 进行检查
【发布时间】:2016-11-23 06:02:23
【问题描述】:

我在 jquery - Post 中有一个问题。当我在表单中输入电子邮件时,js - jquery 会将电子邮件传递到 sendResetPasswordMail1.php 以检查电子邮件是否有效。

但是现在,$.post("sendResetPasswordMail1.php",mail:email},function(resetPasswordMsg) 不能在js中工作了。

我找不到哪里错了。苦恼。 请问你能帮帮我吗。 非常感谢。

php

<!--reset Password Popup start-->
    <div class="resetPasswordLayer" id="resetPassword" tabindex="-1">
        <div class="resetPasswordLayerWall" id="resetPasswordLayerWall">
            <button type="button" class="close resetPasswordCloseButton" aria-label="Close"><span aria-hidden="true">&times;</span></button>
            <p><h3 class="layerTittle">Reset Password</h3></p>
            <div class="row">
                <!--<form class="form-horizontal" action="ResetPassword/sendResetPasswordMail.php" method="post" id="login-form">-->
                    <div class="form-horizontal form-group">
                        <div class="input-group">
                            <p><strong>User can retrieve the password through the mailbox</strong></p>
                            <!--<p><strong>Enter your registered e-mail, retrieve your password:</strong></p>-->
                            <p><input type="text" class="form-control" name="resetPasswordEmail" id="resetPasswordEmail" placeholder="Enter your registered e-mail, retrieve your password."><span id="chkresetPasswordMsg"></span></p>
                        </div>
                    </div>

                    <div class="form-group">
                        <div class="input-group"><!--<div class="col-md-11 col-md-offset-1">-->
                            <p><input type="button" class="btn  btn-success" id="subSendResetPassword_btn" value="Reset"></p>
                            <!--<button type="submit" class="btn btn-success"id="subSendResetPassword_btn">Reset</button>-->
                            <span id="resetPasswordMsg"></span>
                        </div>
                    </div>
                <!--</form>-->
            </div>
        </div>
    </div>
    <!--reset Password Popup End-->

js - jquery

$(function(){
    $("#subSendResetPassword_btn").click(function(){
        var email = $("#resetPasswordEmail").val();
        var preg = /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/; //match Email
        if(email=='' || !preg.test(email)){
            $("#chkresetPasswordMsg").html("Please fill in the correct email!");
        }else{
            $("#subSendResetPassword_btn").attr("disabled","disabled").val('Submit......').css("cursor","default");
            alert(email);
            $.post("sendResetPasswordMail1.php",{mail:email},function(resetPasswordMsg){
                if(resetPasswordMsg == ""){
                    alert("No Msg Return!");
                }

                if(resetPasswordMsg=="noRegister"){
                    $("#chkresetPasswordMsg").html("The mailbox is not registered yet!");
                    //$("#subSendResetPassword_btn").removeAttr("disabled").val('Submit').css("cursor","pointer");
                }else{
                    $(".resetPasswordLayer").html("<h3>"+resetPasswordMsg+"</h3>");
                }
            });
        }
    });
})

php - sendResetPasswordMail1.php

$email = stripslashes(trim($_POST['mail']));
$sql = "select * from user where email='$email'";
$query = mysql_query($sql);
$num = mysql_num_rows($query);
if($num==0){//The mailbox is not registered yet! Return 'noRegister'
    $resetPasswordMsg = "noRegister";
    echo $resetPasswordMsg;
    exit;   
}

【问题讨论】:

  • mysql 语法被贬低并从 php use mysqli 或 pdo 中删除

标签: javascript php jquery ajax post


【解决方案1】:

阻止默认点击事件

$("#subSendResetPassword_btn").click(function(e){
   e.preventDefault()
});

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-07-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多