Form submit without refresh using jquery/ajax if page have more than one form

前端 未结 4 880
抹茶落季
抹茶落季 2020-12-11 10:14

Hi all I know that its very easy to submit a form without refreshing if there is only one form on the page but what about if there are more than one form on the page. Im usi

4条回答
  •  南方客
    南方客 (楼主)
    2020-12-11 10:31

    Add form_id while calling processForm(form_id) and using the id serialize the form.

    function processForm(form) { 
        $.ajax( {
            type: 'POST',
            url: form_process.php,
            data: $(form).serialize(),
            success: function(data) {
                $('#message').html(data);
            }
        } );
        return false;
    }
    

    jsFiddle

提交回复
热议问题