How to stop form submit during ajax call

前端 未结 7 1296
耶瑟儿~
耶瑟儿~ 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:31

    return false or event.preventDefault should help you:

    $('#form1').submit(function(){
        $.ajax({
            url:'some.php',
            type:'POST',
            data:somedata,
            success:function(msg){
            if(!msg){
                //i wanna to stop form1 submit here,how to do that?  you can only modify the code in the ajax call
            }
        }
        });
        return false;
    });
    

    or:

    $('#form1').submit(function(e){
        e.preventDefault();
        $.ajax({
            url:'some.php',
            type:'POST',
            data:somedata,
            success:function(msg){
            if(!msg){
                //i wanna to stop form1 submit here,how to do that?  you can only modify the code in the ajax call
            }
        }
        });
    });
    

提交回复
热议问题