Ir para conteúdo

POWERED BY:

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

rdsat

User Online + Ajax

Recommended Posts

Seguinte galera.. tenho no bd do site uma tabela de usuarios online e gostaria que com o script php o ajax ficasse lendo esta tabela de modo a mostrar os user onlines.script.jsvar req;function loadXMLDoc(url){ req = null; // Procura por um objeto nativo (Mozilla/Safari) if (window.XMLHttpRequest) { req = new XMLHttpRequest(); req.onreadystatechange = processReqChange; req.open("GET", url, true); req.send(null); // Procura por uma versão ActiveX (IE) } else if (window.ActiveXObject) { try {req = new ActiveXObject("Msxml2.XMLHTTP.4.0"); //alert(req);} catch(e) {try {req = new ActiveXObject("Msxml2.XMLHTTP.3.0"); //alert(req);} catch(e) {try {req = new ActiveXObject("Msxml2.XMLHTTP"); //alert(req);} catch(e) {try {req = new ActiveXObject("Microsoft.XMLHTTP"); //alert(req);} catch(e) {req = false;}}}} if (req) { req.onreadystatechange = processReqChange; req.open("GET", url, true); req.send(); } }}function processReqChange(){ // apenas quando o estado for "completado" if (req.readyState == 4) { // apenas se o servidor retornar "OK" if (req.status == 200) { // retornado nela, como texto HTML document.getElementById('user').innerHTML = req.responseText; } else { alert("Houve um problema ao obter os dados:\n" + req.statusText); } }}function buscarTempo(){ loadXMLDoc("user.php");}// Recarrega a cada 60000 milissegundo (60 segundos)setInterval("buscarTempo()", 60000); user.php<?phpheader("Cache-Control: no-store, no-cache, must-revalidate");header("Cache-Control: post-check=0, pre-check=0", false);header("Pragma: no-cache");$sql = mysql_query("select * from useronline"); ?><table width="400" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="133">IP</td> <td width="267">USUARIO</td> </tr><?php//while($linha=mysql_fetch_array($sql)) { $strip = $linha["ip"]; $struseronline = $linha["usuariolog"];?> <tr> <td><?php echo"$strip"?> </td> <td><?php echo"$struseronline"?> </td> </tr> <?php } ?> </table>index.html<html><script language="javascript" type="text/javascript" src="script.js"></script><div id="user"></div></html> O problema e que ele nao esta exibindo os dados..

Compartilhar este post


Link para o post
Compartilhar em outros sites

Cara... não sei qual a sua estrutura ai... eu copiei seu script e modifiquei os selects pro meu banco... e FUNCIONOU...Ah, alterei tb o // do comentario do while e adicionada a linha de conexão ao banco.

Compartilhar este post


Link para o post
Compartilhar em outros sites

×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.