繁体   English   中英

使用单击事件在控制台日志中显示响应

[英]Using click event to show response in console log

我正在跟踪一个允许用户重设密码的链接,但是,到目前为止,我所做的一切都无法正常工作,并且由于我在紧跟本教程,因此我无法弄清楚为什么。 到目前为止,我一直在使用javascript和html,但控制台中没有错误,因此我不确定出什么问题。

HTML

<div class="container-forgotPassword">
    <div class ="row justify-content-center"> 
        <div class="row justify-content-center"> 
            <div class="col-md-6 col-md-offset-3" align="center"> 
             <img id="logologin" src="../img/logo1.png" alt="logo"/>
                <input class="formPassword" id="email" placeholder="Please enter your Email Address"> 
                <input type="button" class="btn-forgotPassword" value="Reset Password"> 
            </div>
        </div>
    </div>
</div><!-- /container -->

jQuery的

var email = $("#email");
$(document).ready(function () {
$('.btn-forgotPassword').on('click', function () {
    if (email.val() != "") {
        email.css('border', '1px solid green');

        $.ajax({ 
            url: 'php/forgotPassword.php',
            method: 'POST',
            dataType: 'text',
            data: { 
                email: email.val()
            }, success: function (response) { 
                    console.log(response);
            }
        });
    } else 
        email.css('border', '1px solid red');
});
});

到目前为止,在本教程中,他已经获得了输入框为绿色/红色,当他在输入字段中输入文本然后单击按钮时,它将在控制台日志中创建一个响应。 但是正如我所说的,我什么也没做,有人知道我该如何解决? 不知道我在做什么错

  1. 您需要在ajax中进行error回调以显示错误

  2. 你想念。 jQuery ajax中没有名为method参数。 这应该是type

$.ajax({ 
    url: 'php/forgotPassword.php',
    type: 'POST', //not method
    dataType: 'text',
    data: { 
        email: email.val()
    }, success: function (response) { 
            console.log('success');
            console.log(response);
    }, error: function(response){
        console.log('error');
        console.log(response); //get all error response
        console.log(response.responseText);//get error responseText
    }
});

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM