2013-07-19 37 views
2

请你能帮助我我有下面的JavaScript代码一切正常,罚款电子邮件验证工作正常,但当访问者输入电子邮件地址并点击注册按钮确认消息'你会通知我们最新的活动!'没有出现。电子邮件提交按钮后的JavaScript/Php没有回应

$(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-\.][email protected]([\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

您只有一个成功处理程序。你需要一个错误处理程序。它看起来像你的AJAX呼叫实际上正在经历,但作为错误返回并且$.ajax呼叫无法报告它。 Read down to 'error'此处查看错误处理程序的外观。您还应该在成功和错误处理程序的开始处设置一个中断点,以确保至少调用其中一个中断点。

+0

你可以给我的代码请 –

+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. :('); 
     } 

    }); 

编辑:你必须添加“”收盘后成功的功能。

+0

这似乎会引起一个错误 –

+0

在成功功能后添加逗号..可能是那个细节 – Hernandcb

+0

我在哪里可以把它作为它仍然不工作? –