Hi guys,
Somthing is really doing my head in.
I have used XMLHttpRequest loads of times using "GET", but i'm trying to use "POST" for a login script.
The strange thing is -- it works, like 80% of the time, but sometimes it just dosnt work.. until the server returns this error:
The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator,
Here is my code:
I have a button on my page:
<input type="button" name="buttonA" onclick="login()" id="buttonA" value="Login" />
I have these two form fields, but no actual form:
<input class="textfield" name="uname" type="text" id="uname" size="15" />
<input name="passwordA" type="password" class="textfield" id="passwordA" size="15" maxlength="15" />
The Ajax/Javascript part:
<script type="text/javascript" language="javascript">
function createRequestObject() {
var httpRequest;
if (window.XMLHttpRequest) { // Mozilla, Safari, ...
httpRequest = new XMLHttpRequest();
} else if (window.ActiveXObject) { // IE
httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
}
return httpRequest;
}
var http = createRequestObject();
function login(){
var params = document.getElementById("buttonS").value;
var url = "load.php";
http.open("POST", url, true);
http.onreadystatechange = resultLoaded;
http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
http.setRequestHeader("Content-length", params.length);
http.setRequestHeader("Connection", "close");
http.send(params);
}
function resultLoaded(){
if(http.readyState == 4){
if(http.responseText == 'login'){
window.location = '/intro/';
}else{
document.getElementById("error").value = http.responseText;
}
}else if(http.readyState == 200){
window.location = '/problem/';
}
}
</script>
The load.php checks the users input to see if they exist in the database.
How does my javascript code look? If that looks ok, i know it is the php "load.php" page.
Any help would be great!
Many thanks.