How to submit a specific form if multiple forms are present in one page using jquery

后端 未结 6 2091
-上瘾入骨i
-上瘾入骨i 2021-02-14 09:49

I have two forms.

6条回答
  •  遥遥无期
    2021-02-14 10:06

    I usually avoid the .submit() function as i almost always have to do something more with response that .submit() would allow me to do.

    Thus, a non .submit option where you SUBMIT buttons would have to be changed to normal buttons.

    $('.btn2').bind('click', function(){
    
        var form1Data = $('#frm1').serialize();
        $.ajax({
            url : 'someurl',
            type : 'post',
            datatype : 'json',
            data : form1Data,
            success : function(json) {
                sumbitForm2();
            }
        });
    });
    
    function submitForm2() {
    
        var form2Data = $('#frm2').serialize(); 
        $.ajax({
            url : 'urlToSumbitForm1',
            type : 'post',
            datatype : 'json',
            data : form2Data,
            success : function(json) {
                //do something if you need to
            }
        });
    }
    

提交回复
热议问题