Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
951 views
in Technique[技术] by (71.8m points)

php - 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).

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...