• 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...

Joined
Oct 15, 2006
Messages
847 (0.20/day)
Likes
33
Location
St. Louis, MO
System Name QUAD1
Processor Intel Core i7 920
Motherboard Asus P6T SE
Cooling XIGMATEK HDT-S963
Memory OCZ 3 X 1GB Triple Channel
Video Card(s) HIS Radeon HD4670 IceQ
Storage Seagate 250GB 7200RPM SATA
Display(s) Acer AL1916W 19" Widescreen LCD
Case CM Storm Scout
Audio Device(s) Onboard
Power Supply Corsair 520 Watt
Software Windows XP Pro
#1
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
 
Joined
Oct 15, 2006
Messages
847 (0.20/day)
Likes
33
Location
St. Louis, MO
System Name QUAD1
Processor Intel Core i7 920
Motherboard Asus P6T SE
Cooling XIGMATEK HDT-S963
Memory OCZ 3 X 1GB Triple Channel
Video Card(s) HIS Radeon HD4670 IceQ
Storage Seagate 250GB 7200RPM SATA
Display(s) Acer AL1916W 19" Widescreen LCD
Case CM Storm Scout
Audio Device(s) Onboard
Power Supply Corsair 520 Watt
Software Windows XP Pro
#2
Ok, it's fixed. another member on a another forum caught a spelling error in "response".


Chris