I’m posting data via fetch to a page, it’s doing something with my database and I want to return a JSON message.
Here’s what I’ve got
My Post
“`
fetch(“../process/do_something_.php”,
{
body: formData,
method: “post”
})
.then(response => {
response.json()
})
.then(data => console.log(data));
}
do_something.php
“`
header(‘Content-type: application/json’);
if ($error === 0){
$array = array(‘user’ => $ID, ‘outcome’ => true);
echo json_encode($array);
} else {
$array = array(‘user’ => 0, ‘outcome’ => false);
echo json_encode($array);
}
I’m constantly getting
“VM162:1 Uncaught (in promise) SyntaxError: Unexpected end of JSON input”
What am I doing wrong?