xhttp.send (data) отправляет пустую строку вместо данных. Я смотрю на другие примеры, и это должно работать. Я смотрю на это снова и снова и не могу понять, что не так. Если бы кто-нибудь мог мне помочь, я был бы очень признателен.
<head>
<title>Tuition Reimbursement Management System </title>
</head>
<body>
<h4>User Name</h4>
<input type="text"id="user">
<h4>Password</h4><br>
<input type="password"id="pass">
<button onclick="login()">Login</button>
</body>
<script>
function login(){
let xhttp = new XMLHttpRequest();
let user = document.getElementById("user").value;
let pass = document.getElementById("pass").value;
xhttp.onreadystatechange = function() {
if(this.readyState==4 && this.status==200){
console.log(xhttp.responseText);
}
}
xhttp.open("POST","http://localhost:8080/one/login.do",true);
xhttp.setRequestHeader("Content-Type","application/json");
let employee = {user:user,pass:pass};
data = JSON.stringify(employee);
console.log(employee);// Object { user: "bob", pass: "password" }
console.log(data); //{"user":"bob","pass":"password"}
console.log(xhttp); // empty string
xhttp.send(data)
}
</script>
</html> ```