Search This Blog

Tuesday, May 6, 2008

Ajax login

function MakeCursorHourglass() { document.body.style.cursor = "wait"; } function MakeCursorNormal() { document.body.style.cursor = "default"; } function GetXmlHttpObject() { var xmlHttp = null; try { // Firefox, Opera 8.0+, Safari xmlHttp = new XMLHttpRequest(); } catch (e) { // Internet Explorer try { xmlHttp = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); } } return xmlHttp; } function login() { xmlHttp = GetXmlHttpObject(); var field_info = new Array(); if (xmlHttp == null) { alert ("Your browser does not support AJAX!"); return; } url = "/btree-bin/login.py" field_info[0] = document.getElementById("user").value; field_info[1] = document.getElementById("passwd").value; if (checklogin_validation(field_info[0],field_info[1])==true) { xmlHttp.open("POST",url,true); xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded"); xmlHttp.send("user" + field_info[0] + "&passwd=" + field_info[1]); MakeCursorHourglass() xmlHttp.onreadystatechange = function() { if (xmlHttp.readyState == 4) { userid = xmlHttp.responseText; MakeCursorNormal() if (userid == 0) { var div = document.getElementById("div"); div.innerHTML = 'Invalid Email Address or Password'; } else if (userid == -1) { var div = document.getElementById("div"); div.innerHTML = 'User already Logged In'; } else if (userid == -2) { var div = document.getElementById("div"); div.innerHTML = 'DATABASE ERROR'; } else { //var myHiddenfield = document.getElementById('v'); //myHiddenfield.value = userid; // alert(myHiddenfield.value) window.location.replace("/lic-bin/updateService.py?v=" + userid + ""); //url = "../../../cgi-bin/user/updateService.py" //xmlHttp.open("POST",url,true); //xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded"); //xmlHttp.send("userid=" + userid); } } } } }

No comments: