Answer the question
In order to leave comments, you need to log in
How to add post data to fetch?
Hello, I send a POST request to the server like this
drawTable(store = 1) {
fetch(this.state.data.pricesUrl + `?form_key=${FORM_KEY}`, {
method: 'POST',
mode: 'cors', // no-cors, *cors, same-origin
cache: 'no-cache', // *default, no-cache, reload, force-cache, only-if-cached
credentials: 'same-origin', // include, *same-origin, omits
redirect: 'follow', // manual, *follow, error
referrerPolicy: 'no-referrer',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
store: store
})
})
Answer the question
In order to leave comments, you need to log in
In your execution of the request on the server, you should accept data through
$post = file_get_contents('php://input');
// $post -> JSON строка
let formData = new FormData();
formData.append('store', store);
fetch(this.state.data.pricesUrl + `?form_key=${FORM_KEY}`, {
method: 'POST',
body: formData
})
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question