01-22-2015, 03:20 AM | #1 |
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. |
01-31-2015, 12:48 PM | #2 |
Registered User
Join Date: Jul 2014
Location: Athens, Greece
Posts: 462
|
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!
__________________
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. | 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. | To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. |
02-17-2015, 03:11 PM | #3 |
Registered User
Join Date: Aug 2013
Location: Tempe, AZ
Posts: 47
|
This totally could be chopped down using jquery. Is there any reason why you can't?
__________________
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. -Andrew C 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. 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. |
02-21-2015, 12:52 PM | #4 |
Registered User
Join Date: Jul 2014
Location: Athens, Greece
Posts: 462
|
why you do it this to yourself ????
make it easier with jquery! .ajax() function!
__________________
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. | 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. | To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
How do hide a column using JQuery? | Jack Hard | Java | 3 | 10-09-2014 11:15 PM |
Free Awesome jQuery Count Down/Up Timer Scripts | JavaScriptBank | Javascript | 0 | 04-09-2013 06:09 AM |
jQuery Plugins | Webmastergrace | Web Promotion | 0 | 09-27-2012 09:23 PM |
Problem with jquery and WP | ArtphotoasiA | Javascript | 4 | 04-02-2012 04:38 AM |
Looking For Jquery Expert! Need To Install Videolightbox on My Site $$ | shakemelikeapig | Wanted | 0 | 02-16-2012 02:25 PM |