how to perform some action before submit form via .ajaxForm()?

后端 未结 3 830
刺人心
刺人心 2021-02-15 11:44

i am using ajaxForm() frame work to send my data without reloading my page.

    $(\'#ReplayForm\').ajaxForm({ 

      success : function(data){
             aler         


        
相关标签:
3条回答
  • 2021-02-15 12:10

    Yes, definatly you can handle this situation. you have to call beforesubmit method for this let see one example

    $('#ReplayForm').ajaxForm({ 
             beforeSubmit : function(arr, $form, options){
                 if("condition is true")
                 {
                    return true; //it will continue your submission.
                 }
                 else
                 {
                                   return false; //ti will stop your submission.
                 }
    
              },
              success : function(data){
                  endLoading();
                  if(data.result=="success")            
                  {
                      showSuccessNotification(data.notification);
                  } 
                  else
                  {
                      showErrorNotification(data.notification);
                  }
               }
       });  
    
    0 讨论(0)
  • 2021-02-15 12:18

    Use beforeSend option in JQuery AJAX framework, if the test fails return false should do it.

    $('#ReplayForm').ajaxForm({ 
    
      success : function(data){
             alert("Success");
      },
      beforeSend: function() {
          if(!myFunc()) {
              return false;
          }
      }
    });
    
    0 讨论(0)
  • 2021-02-15 12:21

    You can use the beforeSubmit option

    $('#ReplayForm').ajaxForm({
        beforeSubmit: function (arr, $form, options) {
            //check your conditions and return false to prevent the form submission
            if (!valid) {
                return false;
            }
        },
        success: function (data) {
            alert("Success");
        }
    });
    
    0 讨论(0)
提交回复
热议问题