pau2756 Posted July 22, 2010 Share Posted July 22, 2010 Hi I am new to Ajax and working through a Sams Teach yourslef Ajax, PHP and JavaScript. I have an error with my first Ajax application and was hoping someone could point me in the right direction. I have attached my html page and i have put all the Java script in it to make it easier to read and post. I have also attached the simple server side php page. My error is (the windows debugger reports) "Object required" and points to the line document.getElementById('showtime').innerHTML = timeValue.childNodes[0].nodeValue; timeVal appears to be null but should have been set in the line right above. I am not sure why this doesn't work. I hope someone can point me in the right direction. Thanks Paul [attachment deleted by admin] Quote Link to comment Share on other sites More sharing options...
radar Posted July 22, 2010 Share Posted July 22, 2010 get rid of your var http = thing and change your 2 functions to look like this: function getServerTime() { req=getXMLHTTPRequest(); if (req) { var myurl = 'telltimeXML.php'; myRand = parseInt(Math.random()*999999999); //add a random number to the URL to avoid cache problems var modurl = myurl + "?rand=" + myRand; req.onreadystatechange = useHttpResponse; req.open("GET", modurl, true); req.send(); } } function useHttpResponse() { if (req.readyState == 4) { if (req.status == 200) { var timeValue = req.responseXML.getElementsByTagName("timenow")[0]; document.getElementById('showtime').innerHTML = timeValue.childNodes[0].nodeValue; } } else { document.getElementById('showtime').innerHTML = '<img src="anim.gif">'; } } and see if that works.. also make sure the php file called is really there. if this doesnt work for you, its going to be an issue in the php file itself. Quote Link to comment Share on other sites More sharing options...
pau2756 Posted July 22, 2010 Author Share Posted July 22, 2010 Hi Thanks for the speedy help. I found the fault - it was a speeling mistake in the php serever file. I put headr instead of header. Once i am up and runniing a bit better i will look into setting up stepping through the code ao the server side. Until then i will muddle through and thanks again. Paul 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.