I am utilizing the fetch()
method to send an ajax request to my server. However, when I use request.POST
, it returns an empty QueryDict
instead of my actual data which is returned by request.body
. Can anyone help me figure out what I'm doing wrong?
Below is a snippet of my JavaScript code:
fetch(url, {
method: "post",
credentials: 'same-origin',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
'X-CSRFToken': csrftoken,
'X-Requested-With': 'XMLHttpRequest'
},
body: JSON.stringify(data)
})
.then(async res => ({
status: res.status,
body: await res.json(),
isOk: res.ok
}))