I am posting to PHP file an OBJECT, the question is, I am not using name="" like when we do it inside the forms, but Instead, I am posting an Object, look:
const done = async obj => {
console.log("sending JSON to PHP...");
await fetch("myFile.php",
{
method: "post",
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(obj)
}
)
}
let obj = {
email: "ahmad@example.com",
message: "salam"
}
const send = async (obj)=>{
let response = await done(obj);
}
send(obj);
The question is, How the PHP will resolve the posted arguments?
here is what I've tried:
$email = $_POST['email'];
$message = $_POST['message'];
but as usual, this isn't working.
[EDIT]:
Extra question: is it important to send the POSTED data as JSON format? Is it important to do that while using the fetch API?