Site Owners Forums - Webmaster Forums

Site Owners Forums - Webmaster Forums (http://siteownersforums.com/index.php)
-   Javascript (http://siteownersforums.com/forumdisplay.php?f=24)
-   -   Ajax without jQuery (http://siteownersforums.com/showthread.php?t=151469)

rakesvyas44 01-22-2015 03:20 AM

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.display = ""none"";
document.getElementById(""SignInButton"").value=""please wait.."";
document.getElementById(""SignInButton"").setAttribute(""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.display = ""block"";
document.getElementById(""staffErrorBox"").innerHTML=""Error"";
document.getElementById(""SignInButton"").value=""Sign In"";
document.getElementById(""SignInButton"").removeAttribute(""disabled"");
} else {
document.getElementById(""SignInButton"").value=""Sign In"";
document.getElementById(""SignInButton"").removeAttribute(""disabled"");
}


}
});
}"

george.web13 01-31-2015 12:48 PM

So, what is the problem?
is it working ok for you? keep it!

But with jquery, you could do this, with a lot less code!

andrewc 02-17-2015 03:11 PM

This totally could be chopped down using jquery. Is there any reason why you can't?

george.web13 02-21-2015 12:52 PM

why you do it this to yourself ????
make it easier with jquery! .ajax() function!


All times are GMT -7. The time now is 06:17 PM.


Powered by vBulletin Copyright © 2020 vBulletin Solutions, Inc.