const response = await fetch('/sign-up', options);
const responseJson = await response.json().then(function(){
})
const status = responseJson.status;
if(status == 'created'){
alert('Account has successfully created')
}else if(status == 'exist'){
if(responseJson.Username){
$("#Username").css('box-shadow', 'inset 0 0 0 1px #DE071C');
$("#Username").css('background-color', '#EEEFF1');
$("#Username_error").css('display', 'block');
document.getElementById('text_Username_error').innerHTML = "This ID already exists. Please choose a different ID"
}
if(responseJson.Email){
$("#Email").css('box-shadow', 'inset 0 0 0 1px #DE071C');
$("#Email").css('background-color', '#EEEFF1');
$("#Email_error").css('display', 'block');
document.getElementById('text_Email_error').innerHTML = "This email already exists. Please choose a different email"
}
}else if(status == 'error'){
$("#error").css('display', 'block');
}
I'm sending a request with 'post' method by using a fetch(), and the server will response by sending a json file to the client. I've checked the json file with console.log(responseJson)
and it works just fine. Client receives the json file perfectly, but the if statement after receiving doesn't work.
responseJson.Username
or responseJson.Email
is not the problem, because console.log shows the output perfectly. I think if statement ends before receiving data, but I can't figure out how to solve this. poor me....