What makes request payload an Object Object?
-
Hello everyone!
I make a request to the server that should send id and rating
the code looks like this
const like = document.querySelectorAll('.like'); like.forEach(item => { item.addEventListener('click', (e) => { e.preventDefault(); const fAction = e.target.dataset.act, // TODO thisParId = e.target.dataset.id; fetch(fAction, { method: 'POST', headers: { 'Content-Type': 'application/json', 'X-CSRF-Token': globalData.token, }, body: { review_id: thisParId, rating: 'like', } }); }); });
here is the network
why is the request payload object object and why is the request payload and not the form dataJavaScript Jasper Moss, Dec 5, 2019 -
In body you can pass
1. String (for example, in JSON format),
2. FormData object to send data as form / multipart,
3. Blob / BufferSource for sending binary data,
4. URLSearchParams for sending data in x-www-form-urlencoded encoding, rarely used.
fetch
Example:
body: JSON.stringify (data)
why request payload and not form data
- it depends on the headersNicholas Warren
1 Answers
Your Answer
To place the code, please use CodePen or similar tool. Thanks you!