AJAX log ind virker ikke i IE & Chrome
HejsaJeg har lavet en lille log ind form, der validere med AJAX, så den skriver resultatet med det samme. Det virker fint i FF, men ikke i IE & Chrome... Nogen der har en løsning på det?
Index.php
<html>
<head>
<script src="login.js"></script>
</head>
<body>
<form action="#">
Username: <input type="text" id="user" /><br />
Password: <input type="password" id="pass" /><br />
<input type="submit" value="Check!" id="e" onClick="LoginTry(user.value, pass.value)" />
</form>
<p>Suggestions: <span id="LoginError"></span></p>
</body>
</html>
Login.js
var xmlhttp
function LoginTry(user, pass)
{
xmlhttp=xmlhttp=GetXmlHttpObject();
if (xmlhttp==null)
{
alert ("Your browser does not support XMLHTTP!");
return;
}
var url="login.php";
url=url+"?user="+user;
url=url+"&pass="+pass;
xmlhttp.onreadystatechange=stateChanged;
xmlhttp.open("GET",url,true);
xmlhttp.send(null);
}
function stateChanged()
{
if (xmlhttp.readyState==4)
{
var result = xmlhttp.responseText.split("|");
var Error = result[0];
var Msg = result[1];
if(Error==1)
{
//document.getElementById("txtHint").innerHTML="Korrekt!";
window.location.href="index.php?login=1";
}
else{
document.getElementById("LoginError").innerHTML=Msg;
}
//document.getElementById("txtHint").innerHTML=xmlhttp.responseText.split("|");
}
}
function GetXmlHttpObject()
{
if (window.XMLHttpRequest)
{
// code for IE7+, Firefox, Chrome, Opera, Safari
return new XMLHttpRequest();
}
if (window.ActiveXObject)
{
// code for IE6, IE5
return new ActiveXObject("Microsoft.XMLHTTP");
}
return null;
}
Login.php
<?php
$user = stripslashes($_GET['user']);
$pass = stripslashes($_GET['pass']);
$RightUser = "Niclas";
$RightPass = "1234";
if($user == $RightUser && $pass == $RightPass)
{
$response = 1;
}
else
{
$response = "0|Der skete en fejl!";
}
echo $response;
?>