Below is code for fetch in javascript:
fetch(url + "?" + o)
.then(response => {
if (response.ok) {
resolve(response.text());
} else {
reject(response.json()); ///issue in read json data how to read json?
}
})
.then(html => {
debugger
document.getElementById('partialresult').innerHTML = html;
})
.catch(err => {
debugger
console.log("Can’t access " + url + " response. Blocked by browser?" + err)
´
document.getElementById('partialresult').innerHTML = err;
});
I need to read json if (!response.ok) i need to read the json data in catch or any where just div need to updated..
Return Json format:
{ success = false, message = "Operation failed." }
How to read json in fetch?
EDIT : server return succees in html and failure( error) in json ..html working fine and i need parse json data if failure case show in div
resolve(response.text());... what isresolve- it's not defined anywhere ... perhaps you meantreturn response.text();? as that is how Promises chain