Я хочу отправить форму. В маршруте, когда я использую console.log (req.body), это log {}. Сервер видит этот запрос, корректно добавлен bodyparser. Есть идеи, что случилось?
Мой HTML
<form class='product' id='add'>
<input type="text" class="input1" name="name" placeholder="name">
<input type="text" class="input1" name="type" placeholder="type">
<input type="text" class="input1" name="producer" placeholder="producer">
<input type="file" class="inputImage" name="image" accept="image/jpeg">
<input type="text" class="input1" name="description" placeholder="description">
<button type='button' class='modify' onclick="product.add()"> Add </button>
</form>
мой интерфейс JS
const product.add = () => {
let data = new FormData(document.getElementById('add'));
ajax(data, 'product/add', result => console.log(result));
}
const ajax = (data, url, callback) => {
let xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
callback( JSON.parse( this.response ));
}
};
xhttp.open("POST", url, true);
xhttp.send( data );
};
мои маршруты
router.all('/add', (req, res) => {
console.log(req.body); //here log '{}'
});