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
|
<?php
session_start();
include "".$_SERVER['DOCUMENT_ROOT']."/include/mysql_connect.php";
?>
<script>
$(document).ready(function() {
$("body").on('click', '.chat_profils_homme',function(event) {
event.preventDefault();
var url = $(this).prop('href');
$("#affiche_mess").empty().load(url); // j'apelle le div
setInterval(function() {$("#affiche_mess").empty().load(url); },5000); // je le met à jour toutes les 5 secondes
});
});
$(document).ready(function (e) {
$('#ajoute_mess').on('submit', function(e) {
e.preventDefault();
var $form = $(this);
$.ajax({
url: '/fiche_cli/affiche_mess.php',
method: 'GET',
dataType: 'html',
data: $form.serialize()
}).then(function (data) {
$("#affiche_mess").html(data); // Mise à jour des messages
$.ajax({
url: '/fiche_cli/liste_profil.php',
method: 'GET',
dataType: 'html',
data: $form.serialize()
}).then(function (data) {
$("#list_profil").html(data);
$('.chat_profils_homme').position({
top : '30px'
});
}).catch(function (error) {
console.log(error);
});
document.forms['ajoute_mess'].reset(); // Reset du formulaire
document.getElementById('affiche_mess').scrollTop=document.getElementById('affiche_mess').scrollHeight; // Baisse la scrollbar
}).catch(function (error) {
console.log(error);
});
});
});
document.getElementById('affiche_mess').scrollTop=document.getElementById('affiche_mess').scrollHeight;
</script>
<br>
<div class="chatter">
<div id="list_profil" class="chat_profils">
<?php include "".$_SERVER['DOCUMENT_ROOT']."/fiche_cli/liste_profil.php"; ?>
</div>
<div class="chat_ecrire">
<?php include "".$_SERVER['DOCUMENT_ROOT']."/fiche_cli/ajoute_mess.php"; ?>
</div>
<div id="affiche_mess" class="messages">
<?php include "".$_SERVER['DOCUMENT_ROOT']."/fiche_cli/affiche_mess.php"; ?>
</div>
</div> |
Partager