filozofunpiri
Centipat
- Katılım
- 13 Temmuz 2022
- Mesajlar
- 104
PHP ve Ajax kullanıyorum.
chat.php sayfasındaki Ajax kodu:
chat.php sayfasındaki Ajax kodu:
PHP:
function sendMessages() {
$.ajax({
type: 'POST',
url: 'sent_messages.php',
data: {
user_id: user_id,
session_name: session_name,
session_id: session_id,
text: text,
},
success: function(response) {
if ($('#chat2').html() !== response) {
$('#chat2').html(response);
keepScrollBarDown();
}
}
});
}
sendMessages();
sentMessages.php sayfasından kodlar
<?php
include 'db.php';
$sender_message=$_POST['text'];
$sender_id=$_POST['session_id'];
$receiver_id=$_POST['user_id'];
if($sender_message!=null)
{
$query = "INSERT INTO messages (sender_id, receiver_id, sender_message) VALUES ('$sender_id', '$receiver_id', '$sender_message')";
$query2 = mysqli_query($db, $query);
}
?>
Son düzenleyen: Moderatör: