Answer the question
In order to leave comments, you need to log in
Why are the requests not getting through?
Good evening. I have a function to save company data, if I move console.log to the bottom of both functions, nothing appears and there are no errors either, I'm confused .. Please tell me what to do?
1. There is data in req.body
2. Inside the sql query I can get console.log
Front
$(document).on('click','.save',(e) => {
saveCompany('/save-company')
})
async function saveCompany(url) {
this.url = url
this.options = {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
id: cID,
face: $('.face .value').text(),
physic: $('.physic .value').text(),
index: $('.index .value').text(),
phone: $('.phone .value').text(),
orgn: $('.orgn .value').text(),
region: $('.region .value').text(),
city: $('.city .value').text(),
street: $('.street .value').text(),
bank: $('.bank .value').text(),
bik: $('.bik .value').text(),
rs: $('.rs .value').text(),
ks: $('.ks .value').text()
})
}
console.log('func working')
const response = await fetch(this.url,this.options)
const data = await response.json()
if(data) document.location.replace(`${data.page}`)
}
app.post('/save-company',async (req,res) => {
let face = req.body.face,
physic = req.body.physic,
indexx = req.body.index,
phone = req.body.phone,
orgn = req.body.orgn,
bank = req.body.bank,
bik = req.body.bik,
rs = req.body.rs,
ks = req.body.ks,
id = req.body.id,
region = req.body.region,
city = req.body.city,
street = req.body.street
await pool.query(`UPDATE the_company SET ? WHERE id = '${id}'`,{face,physic,indexx,phone,orgn,bank,bik,rs,ks,region,city,street}, (error,results,fields) => {
if(error) console.log(error)
console.log('ok')
})
console.log(req.body)
return res.send({page: '/control-company'})
})
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question