chief17 Posted August 3, 2009 Share Posted August 3, 2009 Hey guys, Im just starting out with AJAX and i am a little stuck already, please could someone point me in the right direction. Basically nothing is happening, the time is supposed to appear/update when you click anywhere on the page. HTML Page: <html> <head> <script type="text/javascript"> var xmlhttp; //---------------------------------------------------------------------------------------------------------\\ function showTime() { xmlhttp = GetXmlHttpObject(); if (xmlhttp == null) { alert ("Your browser does not support XMLHTTP!"); return; } xmlhttp.onreadystatechange=stateChanged; xmlhttp.open("GET","time.php",true); xmlhttp.send(null); } //---------------------------------------------------------------------------------------------------------\\ //---------------------------------------------------------------------------------------------------------\\ function stateChanged() { if (xmlhttp.readyState == 4) { document.getElementById("timeBox").innerHTML = xmlhttp.responseText; } } //---------------------------------------------------------------------------------------------------------\\ //---------------------------------------------------------------------------------------------------------\\ function GetXmlHttpObject() { if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari return new XMLHttpRequest(); } else if (window.ActiveXObject) { // code for IE6, IE5 return new ActiveXObject("Microsoft.XMLHTTP"); } else { return null; } } //---------------------------------------------------------------------------------------------------------\\ } </script> </head> <body onClick="showTime()"> <div id="timeBox">Click anywhere for the time.</div> </body> </html> PHP code (time.php): <?php echo date("g:i.sa"); ?> Any help is much appreciated. Thanks Quote Link to comment Share on other sites More sharing options...
phpSensei Posted August 3, 2009 Share Posted August 3, 2009 There is no such thing as <body onClick="showTime()"> You cant use that event with the body tag.. try <div id="timeBox"><a href="javascript:showTime()">Click me for the time.</a></div> Quote Link to comment Share on other sites More sharing options...
chief17 Posted August 3, 2009 Author Share Posted August 3, 2009 Hi, Thanks for the reply, onClick with the body tag does actually work so unfortunately that isnt the problem, i however still did try tour tip and sadly it still doesnt work, do you have any other ideas? Thanks Quote Link to comment Share on other sites More sharing options...
watsmyname Posted August 3, 2009 Share Posted August 3, 2009 Hi, Thanks for the reply, onClick with the body tag does actually work so unfortunately that isnt the problem, i however still did try tour tip and sadly it still doesnt work, do you have any other ideas? Thanks you got error in javascript, you got extra "}" in your javascript just above the </script> tag Quote Link to comment Share on other sites More sharing options...
phpSensei Posted August 3, 2009 Share Posted August 3, 2009 Hi, Thanks for the reply, onClick with the body tag does actually work so unfortunately that isnt the problem, i however still did try tour tip and sadly it still doesnt work, do you have any other ideas? Thanks Sorry just never used onclick with the body really... Quote Link to comment Share on other sites More sharing options...
chief17 Posted August 3, 2009 Author Share Posted August 3, 2009 you got error in javascript, you got extra "}" in your javascript just above the </script> tag Hi, Thanks just found that myself, seems to be working now. Thanks for the help guys Cheers Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.