1. Welcome to TechPowerUp Forums, Guest! Please check out our forum guidelines for info related to our community.

Very simple script in AJAX doesn't work...

Discussion in 'Programming & Webmastering' started by aximbigfan, Mar 19, 2008.

  1. aximbigfan New Member

    Joined:
    Oct 15, 2006
    Messages:
    848 (0.29/day)
    Thanks Received:
    35
    Location:
    St. Louis, MO
    I have been trying my hardest, but no matter what, nothing I code with AJAX works :(.

    Here is a very, very simple script just to get the time from a PHP file I have, that echoes the time, and put it in a text box called "timebox". It puts "undefined" in the box instead. I know for a fact fro my servers 404 logs that it is getting all the files it needs, but still.

    Lets just assume that who ever is accessing the page is using Firefox. I'll change it after I get it to work.

    Code:
    <script type='text/javascript'>
    function time()
    {
    var http = new XMLHttpRequest();
    
    http.onreadystatechange=function()
    {
    if (http.readyState==4)
    {
    document.time.timebox.value=http.responceText;
    }
    }
    http.open("GET","../libs/time.php", true);
    http.send(null);
    }
    </script>";
    <form name='time'><input type='text' name='timebox'><input type='button' value='Server Time' name='timebutton'  onclick="document.location.href='javascript:time();'"></form>
    Also, why is it that when I have buttons with functions in them, for example onclick='function()', it never works? I always have to put onclick="document.location.href='javascript:function();'"

    Chris
     
  2. aximbigfan New Member

    Joined:
    Oct 15, 2006
    Messages:
    848 (0.29/day)
    Thanks Received:
    35
    Location:
    St. Louis, MO
    Ok, it's fixed. another member on a another forum caught a spelling error in "response".


    Chris
     

Currently Active Users Viewing This Thread: 1 (0 members and 1 guest)

Share This Page