Jump to content

stuck on what should be a simple thing!


spiderwell

Recommended Posts

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

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!!

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.