[英]JavaScript/ Php no response after email submit button
Please could you help me I have the below javascript code everything works fine email validating works fine but when a visitor types in there email address and click sign up button the confirmation message 'You will be notified with our latest events!' 请您帮我,我有下面的JavaScript代码,一切正常,电子邮件验证正常,但是当访客在此处输入电子邮件地址并单击“注册”按钮时,确认消息“您将收到我们的最新活动通知!” doesn't show up.
没有出现。
$(document).ready(function(){
//Bind JavaScript event on SignUp Button
$('#submitbtn').click(function(){
signUp($('#email').val());
});
var signUp = function(inputEmail)
{
var isValid = true;
var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
if(!emailReg.test(inputEmail)){
isValid = false;
alert('Your email is not in valid format');
}
if(isValid){
var params = {
'action' : 'SignUp',
'email' : inputEmail
};
$.ajax({
type: "POST",
url: "scripts/mail.php",
data: params,
success: function(response){
if(response){
var responseObj = jQuery.parseJSON(response);
if(responseObj.ResponseData)
{
$('#submitbtn').val('');
showMessage('You will be notified with our latest events!');
}
}
}
});
}
};
var mousedownHappened = false;
$("#submitbtn").mousedown(function() {
mousedownHappened = true;
});
$("#email").focus(function(){
$(this).animate({
opacity: 1.0,
width: '250px'
}, 300, function(){
// callback method empty
});
// display submit button
$("#submitbtn").fadeIn(300);
});
$("#email").blur(function(){
if(mousedownHappened) {
// reset mousedown and cancel fading effect
mousedownHappened = false;
} else {
$("#email").animate({
opacity: 0.75,
width: '250px'
}, 500, function(){
// callback method empty
});
// hide submit button
$("#submitbtn").fadeOut(400);
}
});
});
As @Mike said you should add a failure handler to know if there was an error: 正如@Mike所说,您应该添加一个失败处理程序以了解是否存在错误:
$.ajax({
type: "POST",
url: "scripts/mail.php",
data: params,
success: function(response){
if(response){
var responseObj = jQuery.parseJSON(response);
if(responseObj.ResponseData)
{
$('#submitbtn').val('');
showMessage('You will be notified with our latest events!');
}
}
},
error: function(response){
showMessage('Sorry, there was an error saving you email. :(');
}
});
Edit: you have to add a ',' after close success function. 编辑:关闭成功功能后,您必须添加“,”。
You have only an on-success handler. 您只有一个成功的处理程序。 You need an error handler here.
您在这里需要一个错误处理程序。 It looks like your AJAX call is actually going through, but coming back as an error and the
$.ajax
call has no way of reporting it. 看来您的AJAX调用实际上正在进行中,但是作为错误返回,并且
$.ajax
调用无法报告该错误。 Read down to 'error' here to see what the error handler should look like. 在此处阅读“错误” ,以查看错误处理程序的外观。 You should also set a break point at the start of your success and error handlers to make sure that at least one of them is called.
您还应该在成功和错误处理程序的开始处设置一个断点,以确保至少调用了其中一个。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.