...

View Full Version : New to ajax...



Darkfortune
03-18-2011, 07:04 PM
Hi!
I posted this on JavaScript but they didn't answer...
Here's my code, It doesn't work but it needs to load a php file every 0.5 seconds and then put it in a div called content.
I'm new to Ajax & JavaScript so it is a bunch of snippets merged together =/

function refresh()
{
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("content").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open('GET','chat.php,true');
xmlhttp.send();
setTimeout('refresh()', 500);

venegal
03-19-2011, 07:47 AM
"They" are pretty much the same people that will answer you here.

And the reason "they" didn't answer in your other thread is twofold:

First, it has only been an hour since you opened that other thread (which I deleted, because crossposting violates forum rules). Since you don't pay any of the people here to do your work, you will have to wait until someone chooses to invest their free time in helping you.

Second, "My code doesn't work and I don't know how to fix it" is a really bad incentive for anyone to help you. This is a place for professional exchange, which gives people willing to learn the opportunity to benefit from collective experience. It's not a free coding service.

bullant
03-19-2011, 08:05 AM
It doesn't work but it needs to load a php file every 0.5 seconds and then put it in a div called content.


1) Your problem could be with the code in chat.php

2) you have a syntax error in
xmlhttp.open('GET','chat.php,true');

This tute (http://www.w3schools.com/ajax/ajax_xmlhttprequest_send.asp) might help you



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum