Index.html имеет этот код
function uploadData() {
const y12 = parseFloat(document.getElementById("U2").value);
const y11 = parseFloat(document.getElementById("U1").value);
const x12 = parseFloat(document.getElementById("n2").value);
const x11 = parseFloat(document.getElementById("n1").value);
const bv = parseFloat(document.getElementById("b").value);
fetch('/init', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ y12, y11, x12, x11, bv })
})
.then(response => response.json())
.then(data => {
console.log(data.array);
})
.catch(error => {
console.error('Error:', error);
});
}
item.js вот этот код
let y12, y11, x12, x11, bv;
……………...
app.post('/init', (req, res) => {
//const { y12, y11, x12, x11, bv = req.body;
console.log('Полный req.body:', req.body); // что приходит на сервер
const y12 = req.body.y12;
const y11 = req.body.y11;
const x12 = req.body.x12;
const x11 = req.body.x11;
const bv = req.body.bv;
console.log('После присваивания:', { y12, y11, x12, x11, bv });
});
уже не соображаю. Почему y12, y11, x12, x11, bv undefined в item.js? Нашел ошибку в button теперь в консоли
$ node item.js
Server is running on port 3000
Полный req.body: { y12: 12.3, y11: 4.02, x12: 3.03, x11: 0.9, bv: 0.526 }
После присваивания: { y12: 12.3, y11: 4.02, x12: 3.03, x11: 0.9, bv: 0.526 }
One or more variables are undefined







