D
D
DTHRT2021-02-09 22:46:42
PHP
DTHRT, 2021-02-09 22:46:42

How to send json to php without ajax?

Hello!

There is a form. It is filled in by the user and after clicking on the submit button, all data is sent to the post in the name.php file, which was specified in the action attribute. Generally standard behavior.

Question: How to submit along with JSON form?

What I tried:
JSON.stringify. As a result, we get a string instead of an object at the output. But how can I put it in a php file now?

What I was looking for:
There are a lot of ajax solutions on the Internet, but in my project, immediately after clicking on the "submit" button, the browser should go to the name.php file and there should be access to the JSON file (along with the data from the "name" fields of my forms).

What do I even want to do?
I made a basket on localStorage and linked the payment to YuKassa. I successfully implemented everything, but I can not transfer the goods from the "basket" localStorage. In the name.php file, a request is generated to Yukassu and then a redirect is carried out, so I thought that ajax didn’t seem to suit me ... although maybe I don’t know something.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Slava Rozhnev, 2021-02-09
@DTHRT

What I tried:
JSON.stringify. As a result, we get a string instead of an object at the output. But how can I put it in a php file now?

Fine! We get the string, put the json in a hidden field and send the form to the server.
We get a string in PHP and turn it into a test and share PHP code object
$json = json_decode($_POST['json']);

V
Vasily Bannikov, 2021-02-09
@vabka

After sending the request, you can then go to the desired page. Why not?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question