![]() |
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""); } } }); }" |
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! |
This totally could be chopped down using jquery. Is there any reason why you can't?
|
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.