Is there a way to POST parameters for content type text/html without sending it as an object?
In my specific scenario, I need to include extra data that is not part of a form and is read from a cookie.
When posting with body : {} or body: JSON.Stringify({}), the data is posted as an object. However, I want the data to be posted as individual values.
$(document).on('click', '#update', async () => {
try {
const response = await fetch("/getupdate",{
method:'POST',
headers:{
'Content-Type':'text/html; charset=utf-8'
},
body: JSON.stringify({
"country": getCookie("country"),
"city": getCookie("city").replace(/"/g, ""),
"action": 1,
"csrfmiddlewaretoken": $('input[name=csrfmiddlewaretoken]').val()
}),
});
} catch (error){
console.log(error)
}
});
Instead of receiving individual values, I got an object -
{
"country": "US",
"city": "Miami",
"action": 1,
"csrfmiddlewaretoken": "iLoS4Bsgdyc6EhOtQKiiXrIqr9S1eojdhdyEeClA8qI5ei2WpfQQu1JrduLrbndndR"
}
I am expecting individual values to be sent like this -
"country": "US",
"city": "Miami",
"action": 1,
"csrfmiddlewaretoken": "iLoS4Bsgdyc6EhOtQKiiXrIqr9S1eojdhdyEeClA8qI5ei2WpfQQu1JrduLrbndndR"