I’m trying to post an array of ID’s via fetch then update a database.
Here’s what I have. When I console.log(IDs) I get an array of ID’s as expected.
But my respsonse is an empty array. Any ideas?
“`
const formData = new FormData();
formData.append(‘ID’, JSON.stringify(IDs));
fetch(‘savedata.php’,{
method: ‘POST’,
headers: {
‘Content-Type’: ‘application/json’,
},
body: formData,
}).then(function (response) {
// The API call was successful!
return response.text();
}).then(function (html) {
console.log(html)
}).catch(function (err) {
console.warn(‘Something went wrong.’, err);
});
my savedata.php page
“`
header(‘Content-Type: application/json’);
var_dump($_POST);