Author Topic: Login Form - Ajax / PHP  (Read 629 times)

0 Members and 1 Guest are viewing this topic.

Offline havenpetsTopic starter

  • Irregular
  • Posts: 28
    • View Profile
Login Form - Ajax / PHP
« on: May 19, 2010, 11:20:41 PM »
In Google chrome and Firefox my script works wonders. It looks amazing!

However, in internet explorer there seems to be a minor problem.
Once a login credential has been submitted (e.g. Username: hi, Password: hi) you cannot submit the form again with the same credentials. Seems like a security thing IE does so it's not viewing the same web page as before.

Code:
Code: [Select]
function check_credentials(){   
    httpObject = getHTTPObject();
    if (httpObject != null) {
        httpObject.open("GET", "/xatron/login.php?username="+escape(document.getElementById('username').value)+"&password="+escape(document.getElementById('password').value), true);
        httpObject.send(null);
        httpObject.onreadystatechange = function() { setOutput(); }
    }
}

function setOutput(){
    if(httpObject.readyState == 4){
// alert(httpObject.readyState); *** This is a test line...
        login_run(httpObject.responseText);
    }
}

function login_run(login_answer){
login_answer = login_answer;
if(login_answer == 0){
// alert false
}else{
document.location.href='/xatron/welcome.php';
}

And the form:
Code: [Select]
<table width="90%" cellspacing="0" cellpadding="0">
 <tr>
    <td width="50%">Username:</td>
    <td width="50%"><input type="text" id="username"  /></td>
 </tr>
 <tr>
    <td width="50%">Password:</td>
    <td width="50%"><input type="password" id="password" /></td>
 </tr>
</table>

I am using jquery for the submit, but it's not the jquery giving the problems, it's the AJAX. any advice? Should "get" be "post" maybe?! Not sure.
« Last Edit: May 19, 2010, 11:31:16 PM by havenpets »

Offline havenpetsTopic starter

  • Irregular
  • Posts: 28
    • View Profile
Re: Login Form - Ajax / PHP
« Reply #1 on: May 19, 2010, 11:37:25 PM »
Lol wow why was I thinking forms with the "GET" and "POST" thing? Ha ha Sorry about that!

Offline havenpetsTopic starter

  • Irregular
  • Posts: 28
    • View Profile
Re: Login Form - Ajax / PHP
« Reply #2 on: May 20, 2010, 12:09:43 AM »
I worked around IE's caching...
Code: [Select]
random = Math.floor(Math.random()*999999);
and added
Code: [Select]
+"&random="+random
to the URL so it's a different link every time! :D