let nickname = document.getElementById("nickname");
let status = document.getElementById("status");
nickname.addEventListener("input", () => updateInfo(nickname));
function getCookie(name) {
var cookieValue = null;
if (document.cookie && document.cookie !== '') {
var cookies = document.cookie.split(';');
for (var i = 0; i < cookies.length; i++) {
var 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;
}
function updateInfo(nickname){
nicknameRequest = new XMLHttpRequest();
nicknameRequest.open("POST", "/articles/checknickname/");
nicknameRequest.setRequestHeader("X-CSRFToken", getCookie('csrftoken'));
let params = {
"nickname": nickname
}
nicknameRequest.send(JSON.stringify(params));
nicknameRequest.onprogress = function(event){
status.innerHTML = "...";
}
nicknameRequest.onload = function(){
if (nicknameRequest.status == 200){
status.innerHTML = nicknameRequest.response;
}
}
}
Я распечатал значения post запроса в консоли (когда получаю запрос на сервер) и их не оказалось вовсе.