Answer the question
In order to leave comments, you need to log in
Post comes empty?
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;
}
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question