origaflux Posted July 21, 2008 Share Posted July 21, 2008 Hi. I've been fighting with this login script for a while now and after fixing other errors, the one that sticks involves actually sending the xml request. Internet Explorer 7: "Object doesn't support this property or method" Fire Fox 3: "XMLreq.open is not a function." ajax.js - AJAX initiator function Ajax() { this.init = function() { var i = 0; var reqTry = [ function() { return new XMLHttpRequest(); }, function() { return new ActiveXObject('Msxml2.XMLHTTP') }, function() { return new ActiveXObject('Microsoft.XMLHTTP' )} ]; while (!this.req && (i < reqTry.length)) { try { this.req = reqTry[i++](); } catch(e) {} } return true; }; if (!this.init()) { alert('Could not create XMLHttpRequest object.'); return; } } loginform.php - the actual form and handling JS. <script> function setOutput(){ if(XMLreq.readyState == 4){ if(XMLreq.responseText = 'failure') { alert("Invalid username or password."); alert(XMLreq.responseText.search(/failure/)); } else { document.getElementById("Login").innerHTML = XMLreq.responseText; setTimeout('window.location.reload()', 5000); } } } function sendL(){ var usn = document.getElementById('username').value; var psw = document.getElementById('password').value; document.getElementById("Login").innerHTML = "Processing..."; XMLreq = new Ajax(); if (XMLreq != null) { XMLreq.open("GET", "login.php?username="+usn+"&password="+psw, true); //<--code errors refer to here XMLreq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); XMLreq.onreadystatechange = setOutput; XMLreq.send(null); } else { document.getElementById("Login").innerHTML = "Failed<br />"+ '<a href="Refresh" onClick="window.reload(); return false;">Refresh?</a>'; } } </script> <body> <div id="Login"> <form action="javascript:sendL();" method="post" id="loginForm" onSubmit="sendL();"> Username:<input id="username" name="username" type="text" value="" /><br /> Password:<input id="password" name="password" type="password" value="" /><br /> <input type="submit" id="submitButton" name="submitButton" value="Submit" /> </form> </div> </body> What am I not doing or doing wrong here? Thanks in advance. Quote Link to comment Share on other sites More sharing options...
paul2463 Posted July 21, 2008 Share Posted July 21, 2008 I kno wnothing about AJAX, you are wondering why I am answering here then, I will try and explain using a small amount of programming knowledge I have been looking around on the web for information.... 1. xxx.open is a function call, that is fact 2. for your function to fail it must be that your XMLreq is not an object that .open works with... 3. this tells me that it was not created properly in the first place. 4. something has to be there or the "!= null" would have failed 5. I cant seem to find a function call named "new AJAX()", I have found a xmlReq = new XMLHttpRequest(); .. I might be way off but thats what I thought .... Quote Link to comment Share on other sites More sharing options...
origaflux Posted July 23, 2008 Author Share Posted July 23, 2008 Thanks for the response. My issue, I'm afraid, is not resolved, but the novice error of calling, essentially, a new new XmlHttpRequest(); has been fixed. Quote Link to comment Share on other sites More sharing options...
origaflux Posted July 23, 2008 Author Share Posted July 23, 2008 Sorry about the double post (there's no edit? Yeah, sorry I'm new.) I should clarify my previous post. The script is now telling me as per my programming that it failed. that is: function sendL(){ var usn = document.getElementById('username').value; var psw = document.getElementById('password').value; document.getElementById("Login").innerHTML = "Processing..."; XMLreq = new Ajax(); if (XMLreq != null) { //<--this check.... XMLreq.open("GET", "login.php?username="+usn+"&password="+psw, true); //<--code errors refer to here XMLreq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); XMLreq.onreadystatechange = setOutput; XMLreq.send(null); } else { //<--returns false and goes to the else here. document.getElementById("Login").innerHTML = "Failed<br />"+ '<a href="Refresh" onClick="window.reload(); return false;">Refresh?</a>'; } } </script> As stated above, the check to see if XMLreq is null or not fails (i.e. the script finds it to be null) and it gives me the preprogrammed error message that it failed. So, my new question is: why is the XMLreq null? What new stupid mistake have I done? As always, help is appreciated, and thanks in advance. (edit/sidenote: ah..limited time modify links. I see.) Quote Link to comment Share on other sites More sharing options...
paul2463 Posted July 23, 2008 Share Posted July 23, 2008 you could try and change the check line to read if (XMLreq) because the "if" statement returns either true or false, if the item exists the it is true (code above) if it does not exist then it will fail Quote Link to comment Share on other sites More sharing options...
origaflux Posted July 23, 2008 Author Share Posted July 23, 2008 Yeah it doesn't seem to exist. would it help to modify how i define it? var XMLreq = Ajax(); Or something?.... No error comes up to tell me that the creation of the Ajax() object fails, and yet it doesn't exist.... Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.