2
var dados = {
id: 1234,
nome: "Teste",
tipo: "pagamento"
};
fetch('dados.php', {
method: 'POST',
body: JSON.stringify(dados),
headers: {
'Content-Type': 'application/json'
}
})
I received this help of how to pass data through the fetch
. My question is how to get these values in PHP. I tried print_r(dados)
, but it didn’t work out.
You are sending the data with Content-Type
application/json
. How PHP accepts, by default, data in format urlencoded, it would not be more prudent to send them in this format?– Luiz Felipe
Behold here how to send fields using Content-Type urlencoded using the API
fetch
. If you are using PHP, there is no reason to send in JSON format, since urlencoded is supported natively by the superglobal$_POST
.– Luiz Felipe