Ajax...Class?

  • Creatore Discussione Creatore Discussione Ewan
  • Data di inizio Data di inizio

Ewan

Nuovo Utente
2 Ott 2010
15
0
0
Buongiorno a tutti,
dunque vorrei esporvi un quesito nonché problema di Refresh in Ajax, io vorrei far refreshare SOLO il div che mi interessa quindi la parte PHP che ho dentro un DIV determinata da una class, NO quindi la Class ma solo la parte testuale della Chat.

Fino a qui nessun problema uso questo script:

function Ajax()
{
var
http,
self = arguments.callee;

if (window.XMLHttpRequest) {
http = new XMLHttpRequest();
} else if (window.ActiveXObject) {
try {
http = new ActiveXObject('Msxml2.XMLHTTP');
} catch(e) {
http = new ActiveXObject('Microsoft.XMLHTTP');
}
}

if (http) {
http.onreadystatechange = function()
{
if(http.readyState == 4 && http.status == 200) {
document.getElementById('ReloadThis').innerHTML = http.responseText;
setTimeout(function(){self();}, 5000);
}
};
http.open('GET', pagina.php' + '?' + new Date().getTime(), true);
http.send(null);
}

}

e successivamente richiamo la funzione con lo Script in Chat dopo Body e nel DIV indicato per il refresh, l’unico problema qual è, che il Refresh lo fa ma è come se mi si ristampa di nuovo lo sfondo della chat, come se si sovrapponesse poiché io nel class del DIV (Dove all’interno ho le funzioni in PHP) ho messo un css del tipo <div class=”chat”>, non so se mi son spiegato bene, comunque ci sarebbe un modo per evitare la sovrapposizione dello sfondo del Class e far refreschiare solo la parte PHP della Chat? In modo che lui il refresh lo fa per bene però non mi ristampi lo sfondo.

Grazie mille ^__^
 
Dunque ho modificato tutto, funziona magnificamente l´unico problema è che quando mi si aggiorna la Chat non mi torna sull´ultima frase lanciata ma sulla frase dove sono rimasto bloccato con lo scrool.

Per richiamare la funzione utilizzo questo script:

<script>
var h = 0;
try {
h = parent.chatview.document.body.offsetHeight + 1000;
}
catch(e) {
h = 0;
}
parent.chatview.scroll (0, h);
window.setTimeout("document.location=´chat.php´",60000);
</script>

Ho sbagliato qualcosa?
 
Ecco la Pagina
Codice:
<?php
...
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 <html xmlns="http://www.w3.org/1999/xhtml">
  <head>
   <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

   <title>Chat</title>

 
<script type="text/javascript">
// JavaScript Document
function Ajax()
			{
				var
					http,
					self = arguments.callee;

				if (window.XMLHttpRequest) {
					http = new XMLHttpRequest();
				} else if (window.ActiveXObject) {
					try {
						http = new ActiveXObject('Msxml2.XMLHTTP');
					} catch(e) {
						http = new ActiveXObject('Microsoft.XMLHTTP');
					}
				}

				if (http) {
					http.onreadystatechange = function()
					{
						if(http.readyState == 4 && http.status == 200) {
							document.getElementById('ReloadThis').innerHTML = http.responseText;
							setTimeout(function(){self();}, 10000);
						}
					};
					http.open('GET', 'chat.php?id=<?php echo $_GET['id']; ?>' + '?' + new Date().getTime(), true);
					http.send(null);
				}

			}
</script>

  </head>

  <body> 
  <script type="text/javascript">
			setTimeout(function() {Ajax();}, 10000);
		</script>
        
<div id="ReloadThis">
   
  <div align="center">
       
    <div class="chat" style="width:95%; height:95%;" align="left">
  
	 <?php
	 include('chat_messaggi.php');
	 ?>
     
    </div>
   </div>

    <script>
     var h = 0;
	 try {
		h = parent.chatview.document.body.offsetHeight + 1000;
	 }
	 catch(e) {
		h = 0;
	 }
	 parent.chatview.scroll (0, h);
	 window.setTimeout("document.location='chat.php?id=<?php echo $_GET['id']; ?>'",60000);
    </script>
    </div>
   </div>
   </div>
 </body>
</html>
 

Discussioni simili