Why is it that if I am using Postman, I dont need to include if ($_POST) { '' } else { $_POST = json_decode(file_get_contents('php://input'), true);}
It works differently as If I were to send it from AJAX, but why?
Why doesn't Postman requres json_decode(file_get_contents('php://input'), true);
Ajax code
$.ajax({
url: "http://localhost/WEP/RESTAPI/php.php?api",
type: "POST",
data: JSON.stringify(data),
contentType: "application/json",
success: function(data) {
window.alert("Friend added! "+$name.val()+' '+$email.val());
},
error: function() {
alert("Error");
}
});
PHP
elseif ($srequest == 'POST'){
if ($_POST) {
'';
} else {
$_POST = json_decode(file_get_contents('php://input'), true);
}
$id = $_POST['id'];
$name = $_POST['name'];
$email = $_POST['email'];
//...mysqli connect,query