R
R
RandomProgrammer2021-07-09 22:41:11
JavaScript
RandomProgrammer, 2021-07-09 22:41:11

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;
    }
  }
}


I printed out the values ​​of the post request in the console (when I receive a request to the server) and they were not there at all.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question