Skip to content

Instantly share code, notes, and snippets.

@Inmakia
Created September 4, 2012 08:10
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Inmakia/3618353 to your computer and use it in GitHub Desktop.
Save Inmakia/3618353 to your computer and use it in GitHub Desktop.
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