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 86 87 88 89 90 91 92 93 94 95 96
|
<?php
session_start();
if (isset($_GET['doaction']) && $_GET['doaction'] == 'sessiondestroy') {
session_destroy();
}
?>
<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 updateContent(phrase)
{
var ajaxXhr = getXhr();
ajaxXhr.onreadystatechange = function() {
if (ajaxXhr.readyState == 4 && (ajaxXhr.status == 200 || ajaxXhr.status == 0)) {
document.getElementById('conversContent').innerHTML = ajaxXhr.responseText + "<br/><span style='font-weight:bold; color:#CC0000'><Vous></span> " + phrase; // Donnees textuelles recuperees
}
};
var url = "getcontent.php";
ajaxXhr.open("GET", url, true);
ajaxXhr.send(null);
}
function sendMsg()
{
var phrase = document.getElementById('phrase').value;
updateContent(phrase);
var xhr = getXhr();
document.getElementById('phrase').value = '';
xhr.onreadystatechange = function() {
if (xhr.readyState == 4 && (xhr.status == 200 || xhr.status == 0)) {
document.getElementById('conversContent').innerHTML = xhr.responseText; // Donnees textuelles recuperees
}
};
var url = "iatchat.php";
var data = "phrase=" + phrase
xhr.open("POST", url, true);
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xhr.send(data);
}
</script>
<html>
<head>
<title>
Conversation avec IA Tchat 2.0
</title>
</head>
<body>
<br/><br/>
<div align="center">
<table width="700" style="border: 1px solid" cellspacing="0" cellpadding="0">
<tr>
<td style="border-bottom: 1px solid">
Conversation avec IA Tchat :
</td>
</tr>
<tr>
<td id="conversContent">
</td>
</tr>
</table><br/>
Votre message : <input type="text" id="phrase" size="100" /><br/><br/>
<input type="button" value="Envoyer" onClick="sendMsg()" />
<form method="post" action="index.php?doaction=sessiondestroy">
<input type="submit" value="Vider la session" />
</form>
</div>
</body>
</html> |