[英]Using click event to show response in console log
I am following a link to allow a person to reset a password, however, everything that I have done so far isn't working and I can't figure out why as I am following the tutorial closely. 我正在跟踪一个允许用户重设密码的链接,但是,到目前为止,我所做的一切都无法正常工作,并且由于我在紧跟本教程,因此我无法弄清楚为什么。 I am using javascript and html so far, but there are no errors in the console so i am unsure what is wrong.
到目前为止,我一直在使用javascript和html,但控制台中没有错误,因此我不确定出什么问题。
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 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');
});
});
In the tutorial so far he has gotten the input box to turn green/ red and when he enters text into the input field and then clicks the button it will create a response in the console log. 到目前为止,在本教程中,他已经获得了输入框为绿色/红色,当他在输入字段中输入文本然后单击按钮时,它将在控制台日志中创建一个响应。 But as I said mine is doing nothing, does anyone know how I can fix this?
但是正如我所说的,我什么也没做,有人知道我该如何解决? Not sure what I am doing wrong
不知道我在做什么错
you need error
callback in ajax to show you the error 您需要在ajax中进行
error
回调以显示错误
you miss write. 你想念。 there is no parameter named
method
in jquery ajax. jQuery ajax中没有名为
method
参数。 this should be type
这应该是
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.