Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
JavaScript Login function
function login() {
var user = document.getElementById("user_id").value;
var pass = document.getElementById("pass_id").value;
var req = new XMLHttpRequest();
req.open("POST", "http://192.168.1.63:8000/weather/login/", true);
req.setRequestHeader('Content-Type', 'application/json');
req.withCredentials = true;
req.onreadystatechange = function() {
if (req.readyState == XMLHttpRequest.DONE) {
if (req.status == 200) {
document.getElementById("log_form").style.display = 'none';
document.getElementById("logged_user").style.display = 'block';
document.getElementById("logged_user").textContent = document.getElementById("user_id").value;
document.getElementById("logout_button").style.display = 'block';
hide_error();
}
else if (req.status == 401) {
document.getElementById('error_text').textContent = "User/password is incorrect";
document.getElementById('error').style.display="";
}
}
}
req.send(JSON.stringify({username: user, password: pass}));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.