This file is called main.php.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<!-- Always force latest IE rendering engine (even in intranet) & Chrome Frame
Remove this if you use the .htaccess -->
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<title>main</title>
<meta name="description" content="" />
<meta name="author" content="Blake Teeple" />
<meta name="viewport" content="width=device-width; initial-scale=1.0" />
</head>
<body>
<div id="loginform">
<form method="post">
<table class="block-list">
<tbody>
<tr>
<th><div>Username:</div></th>
<td><input type="text" class="text" id="username" name="username" /></td>
</tr>
<tr>
<th><div>Password:</div></th>
<td><input type="password" class="text" id="password" name="password" /></td>
</tr>
<tr>
<td> </td>
<td style="text-align: right; padding-top: 10px;"><input type="submit" value="Login" onclick="Core.login()"/></td>
</tr>
</tbody>
</table>
</form>
</div>
<script type="text/javascript" src="core.js"></script>
</body>
</html>
As you can see it is very basic, but it gets the job done.
Here is my Javascript file including my Ajax server request.
This file is called core.js.
Core.login = function() {
var username = document.getElementbyID('username'); /*Pulls the username and password to make sure something was entered*/
var password = document.getElementbyID('password');
if(username.value != null || password.value != null){
Core.ajaxserver("login.php", "username: " + username.value + ",password: " + password.value);
}
else{
alert("Error Password or Username")/*displays error message*/
}
}
Core.ajaxserver = function(url, data) { /*Uses ajax to connect to a server to process data. */
var xmlhttp;
if (window.XMLHttpRequest) {
xmlhttp = new XMLHttpRequest(); /*Firefox and other modern browsers. */
} else {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); /*Internet Explorer*/
}
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
data = xmlhttp.responseText.split("|");
for (i = 0; i < data.length; i++){ /*Loop to parse the variables for the server. */
var one = Core.decodeURI(data[parseInt(i)]);
var two = Core.decodeURI(data[parseInt(i) + 1]);
var three = Core.decodeURI(data[parseInt(i) + 2]);
var four = Core.decodeURI(data[parseInt(i) + 3]);
var five = Core.decodeURI(data[parseInt(i) + 4]);
if (window.Core[one]) {
window.Core[one](two,three,four,five);
}
}
} else {
return false;
}
}
if (!data) {
data = "";
}
data = data.replace(/: /gi, "=");
data = data.replace(/:/gi, "=");
data = data.replace(/, /gi, "&");
data = data.replace(/,/gi, "&");
data = data + "¤t_sessionid=" + current_sessionid;
xmlhttp.open("POST",url,true);
xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
xmlhttp.send(data);
}
Core.decodeURI = function (text) {
return decodeURIComponent(text);
}
After troubleshooting and using Alerts to pin point if it was my Javascript or Ajax, I have come to the conclusion I believe it is my Ajax. In my Core.Login() script I put alerts to see if the script was getting the right values, to which it was. My main problem is that I am lost at what is going wrong with my Ajax server request. Any help or advice would be grateful. Thanks.

New Topic/Question
Reply


MultiQuote




|