fetch('https://exampleapid/ehiosunbishop/oshioke/posts', {
method: 'POST',
headers: { "Content-type": "application/json"},
body: JSON.stringify({title:title, thumbnailUrl:thumbnailUrl})
}).then(function(response) {
status = response.status; // Get the HTTP status code
response_ok = response.ok; // Is response.status in the 200-range?
debug_log(response_ok);
return response.json(); // This returns a promise
}).then(function(responseObject) {
debug_log(responseObject["title"]);
}).catch(function(err) {
debug_log(err);
});
}
this returns ‘null’ as response .
someone please help.
and it doesnt add to the datas
You try console.log instead of debug_log?
What does status return?
Try
response.json()
.then(function(data) {
if (status == 200) {
console.log(JSON.stringify(data));
} else {
console.log("not ok");
}
})
.catch(function(error) {
console.log("error");
console.log(error);
});
it still doesnt adds the new datas to my json array
[Viewport]: True
Output the JSON.stringify() of your response.
viewport]: null
i always get null as response and when i check the JSON nothing is added
please help me out
You got a true from the status?
What’s the output of console.log(JSON.stringify(response));
?
…else share your code and the JSON that you’re sending via your backend.