Results 1 to 8 of 8

Thread: Help finding code errors, with AJAX

  1. #1
    Join Date
    Mar 2007
    Location
    Tarboro, NC
    Posts
    290
    Thanks
    8
    Thanked 2 Times in 2 Posts

    Default Help finding code errors, with AJAX

    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:
    Code:
    <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:
    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.
    Wow, I was just reading past posts and man I was a butthole sometimes to people. So if you ever got the end of it, then sorry...

  2. #2
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    Sorry, I'm a newb at ajax, but shouldn't:
    Code:
    xmlhttp.open("GET", "resources/login.php", true);
    Be:
    Code:
    xmlhttp.open("GET", "resources/login.php?"+data, true);
    Sorry if this doesn't help.
    Jeremy | jfein.net

  3. The Following User Says Thank You to Nile For This Useful Post:

    TimFA (05-12-2008)

  4. #3
    Join Date
    Mar 2007
    Location
    Tarboro, NC
    Posts
    290
    Thanks
    8
    Thanked 2 Times in 2 Posts

    Default

    I wish I could say I wasn't...well anyways thanks for giving it a shot, I'll try later. I tried to find help earlier no one ever came up with that idea so it might just work. Thanks !
    Wow, I was just reading past posts and man I was a butthole sometimes to people. So if you ever got the end of it, then sorry...

  5. #4
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    Quote Originally Posted by TimFA View Post
    I wish I could say I wasn't...
    Whats that supposed to mean?
    Jeremy | jfein.net

  6. #5
    Join Date
    Mar 2007
    Location
    Tarboro, NC
    Posts
    290
    Thanks
    8
    Thanked 2 Times in 2 Posts

    Default

    A newb at Ajax lol. I was saying I wish I could say I was good at it, but I'm not.
    Wow, I was just reading past posts and man I was a butthole sometimes to people. So if you ever got the end of it, then sorry...

  7. #6
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    Try this for your code:

    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==4) {
      document.getElementById('login_status').innerHTML=xmlhttp.responseText;
     }
     else {
      document.getElementById('request_status').innerHTML="Attempting to establish a connection...";
     }
    }
    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?"+data, true);
    xmlhttp.onreadystatechange=RSchange;
    xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); 
    xmlhttp.send(null);
    }
    Hope this helps.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  8. #7
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    I'm just curious what worked?
    Jeremy | jfein.net

  9. #8
    Join Date
    Mar 2007
    Location
    Tarboro, NC
    Posts
    290
    Thanks
    8
    Thanked 2 Times in 2 Posts

    Default

    My host went down yesterday with HD failure so I have a bit to wait, they've been down for 8 hours now. o.o; I'll be sure to let you know which one works after I check Nile.
    Wow, I was just reading past posts and man I was a butthole sometimes to people. So if you ever got the end of it, then sorry...

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •