I have a button SIGN INthat onclickcalls a function login(). Inside, login()I call 2 functions:
function login()
{
signin();
statistics_table();
return false;
}
signin();performs the actual signing ( $_SESSION['name']=$username;) ( ajax), and statistics_table();prints a table associated with the user, or a text indicating "please log in to see your statistics" (if the signature did not work) ( ajax).
The problem statistics_table()always prints "please log in ..." . It is as if he signin()had not yet completed the actual signing. Apparently, it only executes it after the function returns login().
So, is there any way to do signin()apply my actions immediately after its completion?
I also tried to make sure that the button calls a function signin(), and statistics_table()one by one, for example:
<input type="submit" value="Sign In" onclick="signin(); statistics_table();">
but that way, when I click the button, it causes the page to reload (again, I need it to be ajax).
Thanks in advance
change
Here is the implementation signin():
function signin()
{
var name = document.getElementById('name').value;
var pw= document.getElementById('password').value;
if (window.XMLHttpRequest)
{
xmlhttp=new XMLHttpRequest();
}
else
{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("Test").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("POST","members.php?name="+name+ "&password="+pw,true);
xmlhttp.send();
return false;
}
source
share