Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Redirect with POST data

I am working on a shopping cart with several payment options using different APIs.

The flow I want is that the user chooses which payment option to use and the according form shows.

On submit the form fields regarding address etc should be saved in my DB and the fields regarding payment is sent with POST to the payment handler api.

It is important that the user only have to click once so the save-in-db has to be squeezed in between the click on the submit button and when the data is sent to the payment server.

I have thought of a redirect where all data gets POSTED to and that save the data in DB and redirect to payment server BUT how do I redirect along with POST data (GET is not working unfortunately).

like image 602
Joseph Avatar asked Nov 21 '25 14:11

Joseph


1 Answers

You can't send a traditional Location: header to the HTTP client to do a redirect and include POST data. What you could do instead is:

  • use an AJAX request to fetch the correct target URL
  • update the form action with that URL via JavaScript (in the AJAX callback function)
  • submit the form
like image 62
AJ. Avatar answered Nov 23 '25 02:11

AJ.



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!