JQuery / Ajax:提交前的验证无效

时间:2015-07-22 10:40:17

标签: javascript jquery ajax validation

我有这个脚本,之前没有验证。我插入了验证脚本,因为它们不起作用。我做错了什么?表单中的数据也不会传输到MYSQL数据库。我还发布了我之前的脚本,没有验证,验证脚本单独在

下面
 $(document).ready(function () {


// just for the demos, avoids form submit
$jQuery.validator.setDefaults({
  debug: true,
  success: "valid"
});
$( "#form-haftpflicht" ).validate({
  rules: {
    versicherungsbeginn: {
      required: true
    },
          erwachsene: {
      required: true
    },
          kinder: {
      required: true
    },
          besitzverhaltnisse: {
      required: true
    },
          garantiesumme: {
      required: true
    },
          geschlecht: {
      required: true
    },
          vornamen: {
      required: true
    },
          nachnamen: {
      required: true
    },
          adresse: {
      required: true
    },
          plz8: {
      required: true
    },
          gemeinde8: {
      required: true
    },
         kanton8: {
      required: true
    },
        geburtsdatum: {
      required: true
    },
        nationalitat: {
      required: true
    },
        telefon: {
      required: true
    },
         email: {
      required: true
    }

  },



            $("#store-haftpflicht").click(function () {
                $("#form-haftpflicht").submit();
            });
            $("#form-haftpflicht").submit(function (event) {
                event.preventDefault();
                $("#ajax-loader").css("display", "block");
                $.ajax({
                    url: 'http://app.lovanet.ch/app/store_haftpflicht.php',
                    data: $(this).serialize(),
                    method: 'POST',
                    success: function (data, status) {
                        $("#ajax-loader").css("display", "none");
                    },
                    error: function () {
                        output.text('Keine Prämien gefunden.');
                    }
                });
            });

            });
        });

这是我的代码,自从验证之前工作正常:

  $(document).ready(function () {
        $("#store-haftpflicht").click(function () {
            $("#form-haftpflicht").submit();
        });
        $("#form-haftpflicht").submit(function (event) {
            event.preventDefault();
            $("#ajax-loader").css("display", "block");
            $.ajax({
                url: 'http://app.lovanet.ch/app/store_haftpflicht.php',
                data: $(this).serialize(),
                method: 'POST',
                success: function (data, status) {
                    $("#ajax-loader").css("display", "none");
                },
                error: function () {
                    output.text('Keine Prämien gefunden.');
                }
            });
        });
    });

这里是验证脚本,我尝试将其集成到提交脚本中。

$jQuery.validator.setDefaults({
  debug: true,
  success: "valid"
});
$( "#form-haftpflicht" ).validate({
  rules: {
    versicherungsbeginn: {
      required: true
    },
          erwachsene: {
      required: true
    },
          kinder: {
      required: true
    },
          besitzverhaltnisse: {
      required: true
    },
          garantiesumme: {
      required: true
    },
          geschlecht: {
      required: true
    },
          vornamen: {
      required: true
    },
          nachnamen: {
      required: true
    },
          adresse: {
      required: true
    },
          plz8: {
      required: true
    },
          gemeinde8: {
      required: true
    },
         kanton8: {
      required: true
    },
        geburtsdatum: {
      required: true
    },
        nationalitat: {
      required: true
    },
        telefon: {
      required: true
    },
         email: {
      required: true
    }

  },
});

0 个答案:

没有答案