Hi I keep getting the error SyntaxError: Unexpected token < in JSON at position 0 I would appreciate your help in finding out what I am doing wrong. My code is as follow:
var rnd = document.getElementById("rnd");
var sendThis = rnd.textContent;
console.log(sendThis);
var URL = "";
const csrftoken = getCookie("csrftoken");
window.onload = () => {
sendit();
};
function sendit() {
console.log("sending");
fetch(URL, {
method: "POST",
credentials: "same-origin",
headers: {
Accept: "application/json",
"Content-Type": "application/json",
"X-Requested-With": "XMLHttpRequest",
"X-CSRFToken": csrftoken,
},
body: JSON.stringify({
'rndValue': 'Test value',
}),
})
.then((response) => {
return response.json();
})
.then((messages) => {
console.log("messages");
})
.catch(error => {
console.log(error);
}
);
console.log("Sent");
}