I use Promise to do a http post. I can see results been output inside then().
How can I access data later? Tried resultPromise.then(), did not produce same result.
let resultPromise =
fetch(cleanUrl, {
method: 'POST', // or 'PUT'
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(body),
})
.then(response => response.json())
.then(data => {
console.log('Success:', data);
})
.catch((error) => {
console.error('Error:', error);
});
//what I intent to do
if(data.isSafe == ture) {
//do something
}
else {
//do somehing
}
Update 1
Added description of what I want to do with data.
Update 2
Move the code inside then() as @Nicholas Tower suggested.