请帮助我,我有以下javascript代码一切正常,电子邮件验证工作正常,但当访问者输入电子邮件地址并点击注册按钮确认消息'您将收到我们最新活动的通知!'不会出现。
$(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);
}
});
});
答案 0 :(得分:1)
正如@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. :(');
}
});
编辑:你必须在关闭成功函数后添加','。
答案 1 :(得分:0)
您只有一个成功处理程序。你需要一个错误处理程序。看起来你的AJAX调用实际上正在通过,但是作为错误返回,$.ajax
调用无法报告它。 Read down to 'error'这里看看错误处理程序应该是什么样子。您还应该在成功和错误处理程序的开头设置一个断点,以确保至少调用其中一个。