Visualizzazione dei risultati da 1 a 2 su 2
  1. #1

    Ajax aggiungere stringa html se nuovo messaggio

    Volevo in una chat invece cha aggiornare tutti i messaggi che aggiungesse solo i messaggi nuovi con poi il php facendo id>$ultimo_mes

    io faccio gia una operazione simile per caricare più discussioni pero la cosa e un po diversa e non sono riuscito ad adattarlo.
    Il codice e il seguente

    codice:
    <script type="text/javascript"> $(function() { $('.more').live("click",function() { var ID = $(this).attr("id"); if(ID) { $("#more"+ID).html('[img]<?php echo $tr_dominio.[/img]attendere.gif" />'); $.ajax({ type: "POST", url: "<?php echo $tr_dominio."/forum/";?>morecategory.php", data: "lastmsg="+ ID, cache: false, success: function(html){ $("#updates").append(html); $("#more"+ID).remove(); } }); } else { $(".morebox").html('
    <span style="background-color:#EEE;padding:5px;border:1px solid #CCC;margin-right:7px;width:100px;">Non ci sono altre discussioni</span>'); } return false; }); }); </script>
    attualmente la chat adopera questo codice che pero se ha immagini si vede il caricamento ed a me non piace ecco:

    codice:
    $(function() { function callAjax(){ $('#agg').load("<?php echo $tr_dominio;?>/forum/chat/aggiorna.php"); } setInterval(callAjax, 2500 ); }); function aggiorna(){ $('#agg').load("<?php echo $tr_dominio;?>/forum/chat/aggiorna.php"); }
    Attendo risposte... Grazie in anticipo

  2. #2
    Dimenticavo codice completo chat senza la pagina aggiorna quella la so fare

    codice:
    <table width="870px" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <td height="200px" style="border:1px solid #DDD;height:200px;width:100%;"> <div id="ricarica"> <link href="<?php echo $tr_dominio;?>/forum/chat/chat.css" rel="stylesheet" type="text/css" /> <script> $(function() { function callAjax(){ $('#agg').load("<?php echo $tr_dominio;?>/forum/chat/aggiorna.php"); } setInterval(callAjax, 2500 ); }); function aggiorna(){ $('#agg').load("<?php echo $tr_dominio;?>/forum/chat/aggiorna.php"); } </script> <div id="agg" height="200px" style="width:100%;height:200px;overflow-x: hidden;overflow-y:scroll"> <style> #mainchat tr { background-color: #FFF; } #mainchat tr:nth-child(even) { background-color: #EEE; } </style> <?php $re=mysql_query("select * from forum_main_chat order by id desc LIMIT 40"); echo "<table id='mainchat' style='width:100%' border='0' cellspacing='0'>"; while($f=mysql_fetch_assoc($re)){ $result=mysql_query("SELECT * FROM members WHERE user = '{$f['username']}'"); $fetch=mysql_fetch_assoc($result); echo "<tr><td width='20'><span class='fecha'>[".$f['data']."]</span></td><td width='20'>[img]".$fetch[[/img]</td>"; ?><td> <span class='usuario'> <span style="color:#<?php if($fetch['activated'] == "0") { echo "000000;";} elseif($fetch['admin'] == "1") { echo "FF0000;";} elseif ($fetch['admin'] == "0.5") { echo "009900;";} elseif ($fetch['admin'] == "0.2") { echo "FFBF00;";} else { echo "0067A5;";}?>"> <?php echo $f['username'].": </span></span></td><td width='650'><span class='mensaje'>".replace_smile(htmlentities($f['messaggio']))."</span></td></tr>"; } echo "</table>"; ?> </div> </div> </td> </tr> <tr> <td align="center"> <div id="form"> <form id="form1" action="<?php echo $tr_dominio;?>/forum/chat/esecuzione.php" name="form1" method="post" onsubmit="xmlhttpPost('<?php echo $tr_dominio;?>/forum/chat/esecuzione.php', 'form1','MyResult', '<img src=\'<?php echo $tr_dominio;?>/forum/include/attendere.gif\'>'); return false;"> <label></label> <label></label> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td>
     <input name="messaggio" type="text" id="messaggio" maxlength="250" style="width:500px;padding:2px;"/> <input class="bt_long" type="submit" name="Submit" value="Invia" style="float:none;display:inline;"> <?php if($_SESSION['admin'] == 1) { ?> <input class="bt_long" type="button" name="Submit" value="Pulisci Chat" style="float:none;display:inline;"> <?php } ?> </td> </tr> </table> </form> <div id="MyResult"></div> </div> </td> </tr> </table>

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2026 vBulletin Solutions, Inc. All rights reserved.