3

I need to send a post request to paypal, but before sending the form I need to verify some inputs and the paypal page must be opened in a new tab or window (doesn't matter). I can't send the request in the same window because in the main page I have background ajax callbacks. So the ideea is can I send the request in a new window or tab?

In all major browesers this isn't allowed, browser keep blocking the request.

<form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_blank" id="paypal_form">
<input type='hidden' name='some_value' id='some_value' value='151' />
</form>

<div id='button_submit' onClick="verify_paypal_form();">SUBMIT !</div>

And now the ajax part:

function verify_paypal_form(){
   $.post('verify.php', { someValue : 'FOO' },
   function(data){
      if( data == 'OKAY' ) $('#paypal_form').submit();
   });
}
Zbarcea Christian
  • 9,367
  • 22
  • 84
  • 137
  • You can use Iframe instead. set the target of the form to that iframe using id. – K D Mar 11 '13 at 09:46

2 Answers2

1

set the target of form to iframe and try it. you can show that iframe as a content of new tab as well.

<form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="myFrame" id="paypal_form">
<input type='hidden' name='some_value' id='some_value' value='151' />
</form>

<div id='button_submit' onClick="verify_paypal_form();">SUBMIT !</div>
<iframe id="myFrame" ...... set other attributes as required....></iframe>
K D
  • 5,889
  • 1
  • 23
  • 35
1

You could open a new window with JS too and then use the solution of this answer:

$("#paypal_form").submit(function() {
    var newWin = window.open("", "", ""); // SPecify your window attributes here, but no URL
    // do an XMLHTPPRequest and document.write the result to the new window:
    var winDoc = doAJAXAndReturnOtherPagesSource();
    newWin.document.write(winDoc);
});
Community
  • 1
  • 1
11684
  • 7,356
  • 12
  • 48
  • 71