Posting/submitting multiple forms in jQuery

后端 未结 1 1496
失恋的感觉
失恋的感觉 2020-12-19 13:33

I have two forms on a page (one is being grabbed by AJAX). I need them both to be posted, so I serialize the second one and send it in a post using jQuery before submitting

相关标签:
1条回答
  • 2020-12-19 14:15

    You might try submitting "first_form" in a callback from the post of "second_form". I believe that the submit of "first_form" is unloading the page which causes the second post to be aborted. Doing the post of "first_form" in the callback from "second_form" will ensure that the initial post is complete before the second post begins.

    $("#submit").livequery('click', function() {
        var form = $("#second_form");
        var action = form.attr("action");
        var serialized_form = form.serialize();
        $.post(action, serialized_form, submit_first);
    });
    
    function submit_first(val) {
       $("#first_form").submit();
    }
    
    0 讨论(0)
提交回复
热议问题