I had written a code to send a response if an email address already exists or a new user has been added. but don't know how to display it in front-end Reactjs.
var updateLimitQuery = `INSERT INTO default_users (userEmail, Role, monthlyGeneral, inflightGeneral, monthlySource, inflightSource) VALUES ("${userEmail}","Default","${tempMG}","${tempIG}","${tempMS}","${tempIS}")`;
connection.query(updateLimitQuery, function(err, result){
if(err)
{
if(err.code == 'ER_DUP_ENTRY' || err.errno == 1062)
{
results = "Entry already exists"
res.send('Entry already exists');
console.log(results)
}
else{
results = "Other error in query"
res.send('SQL query error');
console.log(results)
}
}
else{
results = "New user added"
res.send('New User added');
console.log(results)
}
I want to pick that response in react js either after submit or before submit
Can somebody provide a code for Reactjs to display the response from node js as an alert box or in a variable?
You would use fetch. Example:
fetch("LINK_TO_API")
.then(res => res.json()) //convert response to json format
.then(res => console.log(res)) // console log response
);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.