How to stop form submit during ajax call

前端 未结 7 1300
耶瑟儿~
耶瑟儿~ 2020-11-30 15:09

I can only modify the code in the ajax call. The ajax call occurs when I click the submit in form named $(\'#form1\').

$(\'#form1\').submit(func         


        
7条回答
  •  醉话见心
    2020-11-30 15:26

    Assuming the form's ID is #form1, you could bind a submit handler and return false from it:

    $.ajax({
      url:'some.php',
      type:'POST',
      data:somedata,
      success:function(msg){
        if(!msg){
         $('#form1').submit(function(){
           return false; // prevents form submit
         });
        }
      }
     })
    

提交回复
热议问题