Dethman Posted June 25, 2009 Share Posted June 25, 2009 Hey guys this following AJAX that I made is not doing anything can someone look thru it and tell me where exactly I went wrong? Entire Login Page: <script language="javascript" type="text/javascript"> <!-- //Browser Support Code function ajaxFunction(){ var ajaxRequest; // The variable that makes Ajax possible! try{ // Opera 8.0+, Firefox, Safari ajaxRequest = new XMLHttpRequest(); } catch (e){ // Internet Explorer Browsers try{ ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try{ ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e){ // Something went wrong alert("Your browser broke!"); return false; } } } // Create a function that will receive data sent from the server ajaxRequest.onreadystatechange = function(){ if(ajaxRequest.readyState == 4){ var ajaxDisplay = document.getElementById('ajaxDiv'); var num = ajaxRequest.responseText; if(num = 1){ setTimeout("location.href='redirection.php'", 0); } else{ document.all.main.innerText = "Some random text."; } } } var age = document.getElementById('user').value; var wpm = document.getElementById('pass').value; var queryString = "?age=" + age + "&wpm=" + wpm; ajaxRequest.open("GET", "1/ajax-example.php" + queryString, true); ajaxRequest.send(null); } //--> </script> <tr> <td colspan="3" align="left"><a href="javascript:TINY.box.hide()"><font color="#000;">close login screen</font></a></td> </tr> <div id="wrap"> <div id="top"> </div> <div id="mid"> <div id="content-wrap" align="center"> <form name='myForm'> <table width="200" class="login" cellpadding="0" cellspacing="0"> <tr> <td align="left"><b><font color="red">Login</b></td> <td> </td> <td><div id='main'></div></td> </tr> <tr> <td><font color="black">Username</td> <td><input type="text" name="user" size="16"></td> </tr> <tr class="row2"> <td><font color="black">Password</td> <td><input type="password" name="pass" size="16"></td> </tr> <tr> <td><a href="javascript:ajaxFunction()">LOGIN!</a></td> </table> </form> <div id="bot"> </div> © NimbusGames, LLC. 2009-2015 </div> Ajax-Example.php Page: <?php $user=$_GET['age']; $pass=$_GET['wpm']; if(isset($user){ $gooduser="Tmal"; $goodpass="enterprise"; if($gooduser=$user && $goodpass=$pass){ echo("1"); } else{ echo"2"; } } ?> Any Help with this would be amazing Link to comment https://forums.phpfreaks.com/topic/163693-solved-this-ajax-login-script-is-not-working-very-simple-too/ Share on other sites More sharing options...
Ken2k7 Posted June 26, 2009 Share Posted June 26, 2009 ajaxRequest.open("GET", "1/ajax-example.php" + queryString, true); Is the URL correct? What's 1? Link to comment https://forums.phpfreaks.com/topic/163693-solved-this-ajax-login-script-is-not-working-very-simple-too/#findComment-863826 Share on other sites More sharing options...
MasterACE14 Posted June 26, 2009 Share Posted June 26, 2009 <?php $user = $_GET['age']; $pass = $_GET['wpm']; if(isset($user)) { // missed a parenthesis ) $gooduser = "Tmal"; $goodpass = "enterprise"; if($gooduser == $user && $goodpass == $pass){ // = assigns a value | == checks if two values are equal echo 1; } else{ echo 2; } } ?> Link to comment https://forums.phpfreaks.com/topic/163693-solved-this-ajax-login-script-is-not-working-very-simple-too/#findComment-863939 Share on other sites More sharing options...
xenophobia Posted June 26, 2009 Share Posted June 26, 2009 Try firefox' firebug extension when you working with javascript especially ajax. It help you alot. Link to comment https://forums.phpfreaks.com/topic/163693-solved-this-ajax-login-script-is-not-working-very-simple-too/#findComment-863961 Share on other sites More sharing options...
JasonLewis Posted June 26, 2009 Share Posted June 26, 2009 And, following with what MasterACE14 said, in your ajax code. This: if(num = 1){ Should be: if(num == 1){ So that you are checking to see if num is equal to 1, not setting it to 1. Link to comment https://forums.phpfreaks.com/topic/163693-solved-this-ajax-login-script-is-not-working-very-simple-too/#findComment-863990 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.