开发者

Posting two forms simultaneously using Ajax/jQuery

I have a form that posts to post.php, and a form that posts to Paypal. I want it so that when I click on the Paypal submit button, it posts both forms and goes to the page where the Paypal button would take you.

However, I ran into a wall with this and I'm not sure what the cause is. The form goes to the Paypal page fine, but doesn't POST my other, non-paypal form.

开发者_JAVA百科

Here's my JS: http://slexy.org/view/s2u2Jsr2RI

Here's my HTML: http://slexy.org/view/s2gc4q8CHe

Here's my post.php: http://slexy.org/view/s208WfbKso

Here are the lines of jQuery which I believe to be the root of the issue:

$('#paypalButton').click(function(){
     $.post('post.php', $('#myForm').serialize(), function(){
               $('#paypal').submit();
    });
});


The paypal form is being submitted first because you have the input field as a type="image". That acts as a submit button


This works: just prevent the event's default action of posting the form.

$(function(){
    $('#paypalButton').click(function(**event**){
        **event.preventDefault();** 
         $.post('post.php', $('#myForm').serialize(), function(){
               $('#paypal').submit();
         });
    });
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜