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

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.