wp2
wp2

Reputation: 1421

How to submit two forms this way with jQuery?

<form id="form1">...</form>
<form id="form2">...</form>

I want to submit form1 to host1 first for validation,if the response is true then submit form2 to host2,both should be using POST.

How to do this with jQuery?

Upvotes: 1

Views: 1001

Answers (2)

TJB
TJB

Reputation: 13497

Here's an implementation using AJAX

$("#form1").submit(function(){
    $.post( $(this).attr("action"), $(this).serialize(),
        function(){
            $.post( $("#form2").attr("action"), $("#form2").seriallize(),
                function(){
                    alert("Now what?");
                });
        });
});

Here instead of checking for the response to be 'true' I just assume that it will only have a successful response if the validation passes as 'true'

Upvotes: 1

Headshota
Headshota

Reputation: 21449

Do an AJAX call, on success do another. here is the API Link

Upvotes: 2

Related Questions