Norzy
Новичок
Дата регистрации:
05.03.2017 17:59:59
Сообщений: 1
<html>
<head>
<title>ЧАТ </title>
<style>
h2 {
text-align: center;
}
#chat, table {
margin: 0 auto;
}
#chat {
border: 3px solid #0ff ;
height: 300px;
margin: 0 auto;
overflow-x: none;
overflow-y: auto;
width: 1000px ;
}
p {
margin: 0 ;
color: #953cd1;
}
</style>
<script type="text/javascript"> function
var array = new Array();
function getXmlHttp(){var xmlhttp; try { xmlhttp = new ActiveXObject("Msxm12.XMLHTTP" } catch (e) { try { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP" } catch (E) {xmlhttp = false; } }
if (!xmlhttp && typeof XMLHttpRequest != 'undefined' {
xmlhttp = new XMLHttpRequest();
}
return xmlhttp;
}
function chat() {
var xmlhttp = getXmlHttp();
xmlhttp.open("POST", "functions.php", true);
xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded" );
xmlhttp.send("update=1"
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4) {
if (xmlhttp.status == 200) {
var response = xmlhttp.responseText;
alert(response);
response = JSON.parse(response);
if (array.length == response.length) return;
var start = array.length;
array = response;
var message = document.getElementById("chat".innerHTML;
for (i = start; i < array.length; i++) {
messages = messages + "<p><b>" + array[i]["name"] + ":</b> " + array[i].message + "</p>";
}
document.getElementById("chat".innerHTML = messages ;
}
}
}
setTimeout("chat()", 1000);
}
function addMessage() {
var name = document.getElementById("name".value;
var message = document.getElementById("name".value;
var xmlhttp = getXmlHttp();
xmlhttp.open("POST", "function.php", true);
xmlhttp.setRequesyHeader("Content-type", "application/x-www-form-urlencoded" );
xmlhttp.send("name=" + encodeURIComponent(name) + "&message=" + encodeURIComponent(message));
}
</script>
</head>
<body onload="chat()">
<h2>Это чат</h2>
<div id="chat" >
<p><b>Вася :</b> привет </p>
</div>
<br />
<table>
<tr>
<td> Имя:</td>
<td>
<input type="text" id="name"/>
</td>
</tr>
<tr>
<td>Сообщение</td>
<td>
<input type="text" id="message"/>
</td>
</tr>
<tr>
<td colspan="2">
<input type="button" value="Отправить"/>
</td>
</tr>
</table>
</body>
</html>