I'm working on a project where I have an async function in JS calling to a PHP function, but for some reason it keeps throwing my error function even though I feel I have the syntax correct.
Here is the JS:
async function UpdateBlog() {
var test = "test";
const settings = {
method: 'POST',
body: JSON.stringify({
blog: test
}),
headers: {
'Content-Type': 'application/json',
}
};
var thisurl = baseurl;
const response = await fetch(thisurl, settings);
document.getElementById("scratch").innerHTML = await response.json();
}
And here is what is catching it in PHP
if ($_SERVER["REQUEST_METHOD"] == "POST"){
if(isset($_POST["blog"])){
UpdateBlog($_POST["blog"]);
}
else {
RequestFail();
}
function RequestFail(){
http_response_code(404);
header('Content-Type: application/json');
echo json_encode(false);
}
I have tested the "UpdateBlog" PHP function as a GET and it works, so that's not the issue
Edit: Figured out the first if... statement is being triggered, but it seems that $_POST["blog"] is showing up as empty