Jump to content

Ajax login not updating


adrek

Recommended Posts

Hi,

 

I have an ajax login form that, when submitted, will take the users credentials, send them to my ajax script which will use my php script to authenticate it. My problem is that once the authentication has passed the page will stay the same. I was able to isolate it to this function. If the login is correct it should update the page to say "you are logged in" but you have to submit the form again for it to do anything. I got it to work by adding an alert in there but ideally it should just update the page with out this alert. Does anyone have any suggestions.

 

Thanks

 

 

function login(){
xmlhttpPost("auth.php");
document.getElementById('password').value = "";
alert("");  //Will not work with out this.
if(document.getElementById('status').innerHTML == "1"){
	alert('asdf');
	document.getElementById('content').innerHTML='<font color=\"white\">you are logged in</font>';
}
}

Link to comment
https://forums.phpfreaks.com/topic/183318-ajax-login-not-updating/
Share on other sites

i should prolly show more code.

 

this is the auth.php page

 

<?php
require_once "includes/core.php";
require_once "includes/user.class.php";

$user = new User($_POST['email'], $_POST['password']);
$auth = $user->getAuth();
if($auth)$string = "<font color=\"green\" face=\"Verdana\" size=\"2\">Access Approved</font>";
else $string = "<font color=\"red\" face=\"Verdana\" size=\"2\">Access Denied</font>";

setcookie("auth", $auth);
print $string."<div style=\"display:none\" id=\"status\">$auth</div>";
?>

 

i was trying to play around with setting the values of cookies and divs to see if i could read one of those with the javascript login function but for some reason the js function will not read the cookie or div until the second time it is run through. any ideas?

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.