Register on the forum now to remove ALL ads + popups + get access to tons of hidden content for members only!

Go Back   Site Owners Forums - Webmaster Forums > Web Programming > Programming General > Javascript

Notices


Reply
 
Thread Tools Rate Thread Display Modes
Old 01-22-2015, 02:20 AM   #1
rakesvyas44
Registered User
 
Join Date: Dec 2014
Posts: 13
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"");
}


}
});
}"
__________________
Attorney Jobs | In House Counsel Jobs
rakesvyas44 is offline   Reply With Quote

Old 01-31-2015, 11:48 AM   #2
george.web13
Registered User
 
Join Date: Jul 2014
Location: Athens, Greece
Posts: 475
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!
george.web13 is offline   Reply With Quote
Old 02-17-2015, 02:11 PM   #3
andrewc
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?
andrewc is offline   Reply With Quote
Old 02-21-2015, 11:52 AM   #4
george.web13
Registered User
 
Join Date: Jul 2014
Location: Athens, Greece
Posts: 475
why you do it this to yourself ????
make it easier with jquery! .ajax() function!
george.web13 is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Looking For Jquery Expert! Need To Install Videolightbox on My Site $$ shakemelikeapig Wanted 1 11-12-2017 10:12 AM
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


All times are GMT -7. The time now is 03:09 AM.


Powered by vBulletin Copyright © 2013 vBulletin Solutions, Inc.