spiderwell Posted July 14, 2011 Share Posted July 14, 2011 i have a login form, thats ajax submitted, and response page spits out 0 or 1 on success or failure (of login) but I cant seem to get the jscript to notice the differnce!!. It always executes the else statement from beow. Any ideas? its driving me mad! var dataString = 'username=' + name + '&password='+password; //alert (dataString);return false; $.ajax({ type: "POST", url: "a/a_login.php", data: dataString, cache: false, success: function(html) { alert(html); if (html == "1") { $('#messagebox').html('Login successful, loading site...'+html); $("#messagebox").fadeIn(800); $('#logincontainer').fadeOut(1500); } else { $('#messagebox').html('The username or password was incorrect'+html); $("#messagebox").fadeIn(800); } }, error: function() { $("#messagebox").show(); $('#messagebox').html('There was an error with the login'); } }); return false; Link to comment https://forums.phpfreaks.com/topic/241958-stuck-on-what-should-be-a-simple-thing/ Share on other sites More sharing options...
ZulfadlyAshBurn Posted July 14, 2011 Share Posted July 14, 2011 can you post your a_login.php code? so that we can have a look of what its going to do. Link to comment https://forums.phpfreaks.com/topic/241958-stuck-on-what-should-be-a-simple-thing/#findComment-1242765 Share on other sites More sharing options...
spiderwell Posted July 14, 2011 Author Share Posted July 14, 2011 sure but all it outs puts is 0 or 1. also if i do alert(html) or use .html(html) it puts 1 or 0 into that so I cant work out why javascript isnt executing the if statement correctly. <?php require_once("../../classes/sentry.php"); require_once('../../classes/dbconnector.php'); //create objects for page $connector = new DbConnector(); //create database connection $sentry = new Sentry(); //set up page variables $var_username = ""; //default $var_password = ""; //default if (isset($_POST['username'])) $var_username = $_POST['username']; if (isset($_POST['password'])) $var_password = $_POST['password']; if($sentry->checkLogin($_POST['username'],$_POST['password'],10)) { echo "1"; } else { echo "0"; } I have passed the variables directly to a_login.php in the address bar to check it outputs both 0 and 1, and it does. If i log in correctly i get the message 'The username or password was incorrect 1' the 1 is the html passed back, so in my mind it should be returning the if not the else. if i log in incorrectly i get the message 'The username or password was incorrect 0'. its very annoying!! Link to comment https://forums.phpfreaks.com/topic/241958-stuck-on-what-should-be-a-simple-thing/#findComment-1242796 Share on other sites More sharing options...
spiderwell Posted July 14, 2011 Author Share Posted July 14, 2011 even though I tried this already, it seems to have fixed my issue this time round! odd, but at least I can move on! if (html == "1") changed to if (html == 1) I thought it would have handled the return as a string but perhaps not.. Link to comment https://forums.phpfreaks.com/topic/241958-stuck-on-what-should-be-a-simple-thing/#findComment-1242851 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.