PDA

View Full Version : Very simple script in AJAX doesn't work...


aximbigfan
03-19-2008, 05:12 AM
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.


<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

aximbigfan
03-19-2008, 07:15 AM
Ok, it's fixed. another member on a another forum caught a spelling error in "response".


Chris