jquery验证没有运行Ajax

时间:2015-09-02 12:55:28

标签: javascript jquery ajax

为什么验证在此脚本中不起作用? 我给了空白输入,但它没有给出所需的消息,而且regx也没有用。

$(document).ready(function(){
  var $form = $(this);
  $.validator.addMethod("regx", function(value, element, regexpr) {
    return regexpr.test(value);
  }, "Please enter a valid Pan number.");
  $("#checkval").validate({ //here is form id #checkval
    showErrors: function(errorMap, errorList) {
        for (var error in errorMap) {
            $.growl.error({ message: errorMap[error] });
        }
    },
    onkeyup: false,
    rules: {
        oldemail: {
            required: true,
            regx: /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/
        },
        newemail: {
            required: true,
            regx: /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/
        }
    },
    messages: {
        oldemail: {
            required: "Please enter old e-mail ",
            regx:    "Please enter your valid e-mail address"
        },
        newemail: {
            required: "Please enter new e-mail ",
            regx:    "Please enter your valid e-mail address"
        }       
    },

    // From here started ajax code. 
    submitHandler: function(form) {
            $.ajax({
                url: index.php?act=account,
                type: "POST",
                data: $(form).serialize(),
                success: function(response) {
                    alert(response);
                    $('#inquiryFormHolder').html("Your form was submitted!");
                    // here is div id #inquiryFormHolder
                }            
            });
            $form.submit();
        }
    });
});

0 个答案:

没有答案