tags:

views:

20

answers:

1

Currently the location of my Html is http://severname.com/qotw.html. Onclick of a button i call the login();

the login() javascript function, looks like this:

function login()
{  
  passwrd = document.f_signin.password.value;
  username = document.f_signin.username.value;

  if (username==""){ document.getElementById("response").innerHTML="<font color='red'>Enter your User Name to login.</font>";}
  else if (passwrd==""){ document.getElementById("response").innerHTML="<font color='red'>You did not enter your password. Enter your password and try again.</font>";}

  if (passwrd!="" && username!="")
  {    
    xmlhttp=GetXmlHttpObject();
    //alert("pass");
    if(xmlhttp==null)
    {
      alert("Your browser does not support AJAX!");
      return;
    }
    var url="login.php";
    url=url+"?id="+username+"&passwrd="+passwrd;
    xmlhttp.onreadystatechange=statechangedLogin;
    xmlhttp.open("GET", url, true);
    xmlhttp.send(null);
  }
}

function statechangedLogin()
{
  //alert(xmlhttp.readyState);
  if(xmlhttp.readyState==4)
  {
    if(xmlhttp.responseText=="<font color='red'>Your User Name or Password is incorrect. Please try again.</font>")
    {
      document.getElementById("response").innerHTML=xmlhttp.responseText;
    }
    else 
    {
      document.location="http://servername.com/login.php";
      //document.getElementById("mainbody").
      document.innerHTML=xmlhttp.responseText;
    }
  }
}

I want to display the response from login.php in the location "http://severname.com/login.php"

How should i do this? The location of the page changes from qotw.html to login.php, but the login.php does not displays anything inside it.

Zeeshan

+1  A: 

With

document.location="http://servername.com/login.php";

you advise the browser to request another document from the given url. This new document will replace the current document and your javascript "within" the current document cannot affect the new document (any more).
You're probably setting a cookie to keep track of the session. Why not simply redirect to login.php and have that script check the cookie. If it's a valid session just print something like

You are currently logged in as userXYZ

?

VolkerK
mmm... i type in my username and password. the login.php check if the username and password are correct. if it is it displays more information in the php itself.
Zeeshan Rang
how should i simply redirect to login.php . I want to be redirect to login.php only if the username and password is correct. oherwise the page should remain on the same qotw.html, and the response from login.php is displaying in the "<div name=responce>" tag.
Zeeshan Rang
just drop the document.innerHTML=xmlhttp.responseText; line and let login.php check for the cookie. (btw: consider changing from GET to POST to transmit the user/password data)
VolkerK