Hello everyone!,
After going through a couple of practice with fetch API sessions, I am trying to do a project of my own and need some assistance.
const postData = async (formdata) => {
try {
const response = await fetch('testphp.php',
{
method: 'POST',
body: formdata
});
if (response.ok) {
const data = await response.json()
console.log(data);
}
} catch (e) {
console.log(e);
}
}
So I am able to see an array in console section of the browser and I am seeing this is working. However, could someone help or guide how to write a code that I can call this function totally outside the aysnc function and console only the first item in the array in which it returned?
i tired calling this function as below, i am seeing postData.then is not a function. Please help.
postData.then(value => {
console.log(value);
})