Jump to content

Basic Ajax help


pau2756

Recommended Posts

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]

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.