function getCookie(name) {
let cookieValue = null;
if (document.cookie && document.cookie !== '') {
const cookies = document.cookie.split(';');
for (let i = 0; i < cookies.length; i++) {
const cookie = cookies[i].trim();
// Does this cookie string begin with the name we want?
if (cookie.substring(0, name.length + 1) === (name + '=')) {
cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
break;
}
}
}
return cookieValue;
}
const csrftoken = getCookie('csrftoken');
async function send()
{
let r = await fetch('/blog/third', {method: 'POST',
credentials: 'same-origin',
headers:{'Accept': 'application/json',
'X-Requested-With': 'XMLHttpRequest',
'X-CSRFToken': csrftoken}
});
let res = await r.json();
console.log(res.text);
}
#as you can see, it's much more complicated than GET :)
#but in reality this is probably what you will end up doing
async function send()
{
let r = await fetch('/blog/third', {method: "GET"});
let res = await r.json();
console.log(res.text);
}