View Single Post
Old 01-22-2015, 03:20 AM   #1
rakesvyas44
Registered User
 
Join Date: Dec 2014
Posts: 12
Ajax without jQuery

I've compiled the following code which works at processing my login form using Ajax without jQuery. Just not sure if it's the most efficient way to do it and hoping someone can advise if it can be improved any further.

var xmlhttp;

function loadXMLDoc(url,cfunc) {

if (window.XMLHttpRequest) {
xmlhttp=new XMLHttpRequest();
} else {
xmlhttp=new ActiveXObject(""Microsoft.XMLHTTP"");
}

xmlhttp.onreadystatechange=cfunc;
xmlhttp.open('POST', url, true);
xmlhttp.setRequestHeader(""Content-type"", ""application/x-www-form-urlencoded"");
xmlhttp.send(""username="" + document.getElementById(""username"").value + ""&passwd="" + document.getElementById(""passwd"").value + ""&_SESSION="" + document.getElementById(""_SESSION"").value);

}

function Login() {

loadXMLDoc(""/Login.php"",function() {
document.getElementById(""ErrorBox"").style.displa y = ""none"";
document.getElementById(""SignInButton"").value="" please wait.."";
document.getElementById(""SignInButton"").setAttri bute(""disabled"",""disabled"");
if (xmlhttp.readyState==4 && xmlhttp.status==200) {
var loginResponse = xmlhttp.responseText;

if (loginResponse == 2) {
window.location=""/portal/"";
} else if (loginResponse == 3) {
document.getElementById(""staffErrorBox"").style.d isplay = ""block"";
document.getElementById(""staffErrorBox"").innerHT ML=""Error"";
document.getElementById(""SignInButton"").value="" Sign In"";
document.getElementById(""SignInButton"").removeAt tribute(""disabled"");
} else {
document.getElementById(""SignInButton"").value="" Sign In"";
document.getElementById(""SignInButton"").removeAt tribute(""disabled"");
}


}
});
}"
__________________

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
rakesvyas44 is offline   Reply With Quote