1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
   |  
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
<script type="text/javascript">
function getxhr()
	{
	var xhr = null;
	if (window.XMLHttpRequest || window.ActiveXObject) 
		{
		if (window.ActiveXObject) 
			{
			try 
				{
				xhr = new ActiveXObject("Msxml2.XMLHTTP");
				} 
			catch(e) 
				{
				xhr = new ActiveXObject("Microsoft.XMLHTTP");
				}
			} 
		else 
			{
			xhr = new XMLHttpRequest(); 
			}
		} 
	else 
		{
		alert("Votre navigateur ne supporte pas l'objet XMLHTTPRequest...");
		return null;
		}
	return xhr;
	}
 
function recupe()
	{
	var xhr = getxhr();
 
	xhr.onreadystatechange = function() {
		if (xhr.readyState == 4) {
			var reponse = xhr.responseText;
            document.getElementById("chat").innerHTML = reponse;
 
		}
		setTimeout(recupe,5000);
	};
	xhr.open("POST", "recupe.php", true);
	xhr.send(null);
 
	}
 
function envoi()
	{
	var xhr = getxhr();
	xhr.onreadystatechange = function() 
		{
		if (xhr.readyState == 4 && xhr.status == 200) 
			{
			document.getElementById("status").innerHTML=xhr.responseText;
			}
		};
 	var requete="pseudo="+document.getElementById("pseudo").value+"&message="+document.getElementById("message").value+"&envoi="+document.getElementById("envoi").value;
	xhr.open("POST", "envoi.php", true);
	xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	xhr.send(requete);
	}
 
</script>
</head>
 
<body onLoad="recupe()">
<div>
<div id="status" style="border:1px solid#cccccc;width:200px;height:20px;"></div>
<div id="chat"></div>
</div>
 
<div id="form">
<input type="text" name="pseudo" id="pseudo" maxlength="20" />
<input type="text" name="message" id="message" size="200" maxlength="300" />
<input type="submit" name="envoi" id="envoi" value="Envoyer" onClick="envoi()" />
</div>
</body>
</html> | 
Partager