Możesz zrobić coś takiego jak poniżej
handleSubmit (event) {
//alert('A list was submitted: ' + this.state.formvalue);
event.preventDefault();
fetch('your post url here', {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify({
id: this.state.id,
item: this.state.item,
itemType: this.state.itemType
})
})
.then(res => res.json())
.then(data => console.log(data))
.catch(err => console.log(err);
}
Mój punkt końcowy stanowiska roboczego znajduje się poniżej.
app.post('/api/listitems', (req, res) => {
var postData = req.body;
connection.query('INSERT INTO list_items SET ?', postData, (error, results, fields) => {
if (error) throw error;
res.end(JSON.stringify(results));
});
});