如何在ajax提交表单验证io上放置确认框?

时间:2015-04-08 03:58:38

标签: javascript jquery ajax forms formvalidation-plugin

.on('success.form.fv', function(e) {
    // Prevent form submission
    e.preventDefault();

    var $form = $(e.target),
    fv    = $form.data('formValidation');

    // Use Ajax to submit form data
    $.ajax({
      url: $form.attr('action'),
      type: 'POST',
      data: $form.serialize(),
      cache: false,
      success: function (data, textStatus, jqXHR) {
        alert("Your changes have been saved")
      }
    });
});

我在success.form.fv的{​​{1}}上使用了ajax调用。

在我提交表单之前,如何添加是和否选项的确认对话框?

1 个答案:

答案 0 :(得分:0)

将代码更改为:

.on('success.form.fv', function(e) {
    // Prevent form submission
    e.preventDefault();

    if(confirm('Submit the form ?')){ //user chooses Ok
        /**** Your AJAX code here ****/
    } else {
        // user chooses cancel. Do not submit the form
    }
});