dousou2911 2013-11-14 06:37
浏览 91

使用jquery问题验证和提交表单

I'm trying to submit form using j-query, before submitting it should do some validation and in that I've validation for capcha using ajax. Everything works fine without ajax validation.

<form id="RegistrationForm" name="RegistrationForm" method="post" action="save.php" >

jquery code

$('#RegistrationForm').submit(function(){
//some validation goes here
if($('#captcha').val() != '')
    { 
        var captcha = $('#captcha').val();
        $.ajax({
            url:'validate.php',
            type:'POST',
            data:{captcha:captcha},
            success: function(data){
                if(data == 'false')
                {
                    alert('Wrong Captcha is typed!');
                    return false;
                }
                else
                {
                                alert('enter');
                document.getElementById("RegistrationForm").submit();   
                                return true;

                }

              }
            });
    }
});`

while submitting form it shows alert "enter" but form not getting submitted. Thanks in advance.

  • 写回答

4条回答 默认 最新

  • dqroktbn005028 2013-11-14 06:44
    关注

    You probably need to change your variable to a JSON seening how you are retreiving from a php. if thats not the solution try

    if (data){
    
    }else{
    
    }
    

    FYI this is not jquery validation. Jquery validation is a library set up in order to make sure the proper fields are set up correctly before submitting. What you have done is tested if the captcha is correct after submitting.

    评论

报告相同问题?

悬赏问题

  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 关于#python#的问题:自动化测试