B
B
Bogdan2017-07-20 00:01:23
JavaScript
Bogdan, 2017-07-20 00:01:23

AJAX fetch() pass JSON?

Hello. How to pass d POST JSON object to fetch()

dataValue = { value1: 1, value2: 2 }
const respond = await fetch( url, { method: type, body: dataValue, credentials: 'same-origin' } );

Thanks

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
Bogdan, 2017-07-27
@bogdan_uman

monochromer Presented the correct solution. But due to the fact that it is in the comments I will write the answer

fetch(url, {
  method: "POST",
  body: JSON.stringify(data),
  headers: {
    "Content-Type": "application/json"
  },
  credentials: "same-origin"
})

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question