Skip to content
Advertisement

How to receive Fetch() POST in php?

So i got this POST json method here, but can’t understand how to get my json data

It’s packed in BLOB which is packed in FormData

How to receive such POST in php? (and convert this FormData(Blob) back to json?)

JS

JavaScript

I’m big noobo, so i can’t even receive it

Seems like it works differently with fetch()

PHP

JavaScript

Advertisement

Answer

The simpliest way to send a JSON to server is to simply send it as the POST request body. There is no need to wrap it like a file. For example,

JavaScript

On server side, your message will be readable through the “php://input” stream. You can read it like an ordinary file:

JavaScript

You can save the below code as a PHP file and test it yourself. On load, it would send itself another POST reqeust, parse it as key-value pairs, return it to your browser and show it:

JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement