TimFA
05-11-2008, 10:21 PM
Hey guys,
The below script is all the JavaScript for my page to run, some things are messy and not finished because the site is not finished. Anyways, the AJAX seems to be having some problems. Whenever the function go() is ran the DIV request_status should display "Attempting to establish connection..." but it does not, telling me there is an error somewhere. But higher up functions like the image rollovers and faders work telling me they are not the cause. So that leaves the AJAX area. I'm going to post all the code just in case, I already ran it through JSLint but it didn't produce anything helpful. Any help is appreciated.
Activation area:
<form method=\"post\" action=\"?act=login\">
<input id=\"user\" type=\"hidden\" name=\"user\">
<input id=\"pass\" class=\"passbox\" type=\"password\" name=\"pass\">
<br>
<img id=\"loginbutton\" onClick=\"rollOver('loginbutton','login_click');go();\" onMouseOver=\"rollOver('loginbutton','login_over');\" onMouseOut=\"rollOver('loginbutton','login');\" src=\"resources/images/login.gif\">
</form>
(sorry about the messed up code, with the \'s but its reference from a PHP file so its needed.)
Code:
//Login functions
function selectUser(user) {
document.getElementById("login_users").style.display='none';
document.getElementById("login_pass").style.display='inline';
document.getElementById("user").value='' + user;
}
function backLogin() {
document.getElementById("login_users").style.display='inline';
document.getElementById("login_pass").style.display='none';
document.getElementById("user").value='';
}
//General image/text effects
function fadeIn(image) {
document.getElementById(image).style.opacity='1';
}
function fadeOut(image) {
document.getElementById(image).style.opacity='.5';
}
function rollOver(oldimage,newimage) {
document.getElementById(oldimage).src='resources/images/' + newimage + '.gif';
}
//Ajax request area.
xmlhttp=getHTTPObject();
function getHTTPObject() {
var xhr = false;
if (window.XMLHttpRequest) {
xhr = new XMLHttpRequest();
}
else if (window.ActiveXObject) {
try {
xhr = new ActiveXObject("Msxml2.XMLHTTP");
}
catch(e) {
try {
xhr = new ActiveXObject("Microsoft.XMLHTTP");
}
catch(e) {
xhr = false;
}
}
return xhr;
}
}
function RSchange() {
if (xmlhttp.readyState==1) {
document.getElementById('request_status').innerHTML="Sending data...";
}
else if (xmlhttp.readyState==4) {
document.getElementById('login_status').innerHTML=xmlhttp.responseText;
}
}
function go() {
var user=document.getElementById("user").value;
var pass=document.getElementById("pass").value;
var data="user=" + user + "&pass=" + pass;
xmlhttp.open("GET", "resources/login.php", true);
xmlhttp.onreadystatechange=RSchange;
xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xmlhttp.send(null);
document.getElementById('request_status').innerHTML="Attempting to establish a connection...";
}
Thanks !
Tim.
The below script is all the JavaScript for my page to run, some things are messy and not finished because the site is not finished. Anyways, the AJAX seems to be having some problems. Whenever the function go() is ran the DIV request_status should display "Attempting to establish connection..." but it does not, telling me there is an error somewhere. But higher up functions like the image rollovers and faders work telling me they are not the cause. So that leaves the AJAX area. I'm going to post all the code just in case, I already ran it through JSLint but it didn't produce anything helpful. Any help is appreciated.
Activation area:
<form method=\"post\" action=\"?act=login\">
<input id=\"user\" type=\"hidden\" name=\"user\">
<input id=\"pass\" class=\"passbox\" type=\"password\" name=\"pass\">
<br>
<img id=\"loginbutton\" onClick=\"rollOver('loginbutton','login_click');go();\" onMouseOver=\"rollOver('loginbutton','login_over');\" onMouseOut=\"rollOver('loginbutton','login');\" src=\"resources/images/login.gif\">
</form>
(sorry about the messed up code, with the \'s but its reference from a PHP file so its needed.)
Code:
//Login functions
function selectUser(user) {
document.getElementById("login_users").style.display='none';
document.getElementById("login_pass").style.display='inline';
document.getElementById("user").value='' + user;
}
function backLogin() {
document.getElementById("login_users").style.display='inline';
document.getElementById("login_pass").style.display='none';
document.getElementById("user").value='';
}
//General image/text effects
function fadeIn(image) {
document.getElementById(image).style.opacity='1';
}
function fadeOut(image) {
document.getElementById(image).style.opacity='.5';
}
function rollOver(oldimage,newimage) {
document.getElementById(oldimage).src='resources/images/' + newimage + '.gif';
}
//Ajax request area.
xmlhttp=getHTTPObject();
function getHTTPObject() {
var xhr = false;
if (window.XMLHttpRequest) {
xhr = new XMLHttpRequest();
}
else if (window.ActiveXObject) {
try {
xhr = new ActiveXObject("Msxml2.XMLHTTP");
}
catch(e) {
try {
xhr = new ActiveXObject("Microsoft.XMLHTTP");
}
catch(e) {
xhr = false;
}
}
return xhr;
}
}
function RSchange() {
if (xmlhttp.readyState==1) {
document.getElementById('request_status').innerHTML="Sending data...";
}
else if (xmlhttp.readyState==4) {
document.getElementById('login_status').innerHTML=xmlhttp.responseText;
}
}
function go() {
var user=document.getElementById("user").value;
var pass=document.getElementById("pass").value;
var data="user=" + user + "&pass=" + pass;
xmlhttp.open("GET", "resources/login.php", true);
xmlhttp.onreadystatechange=RSchange;
xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xmlhttp.send(null);
document.getElementById('request_status').innerHTML="Attempting to establish a connection...";
}
Thanks !
Tim.