Why not sent data from php script through ajax?

Trying to make a little chat, not sent with the data input, I can not understand in what business. The console gives an empty string.

The form itself:
<form class="chat">
 <div class="input-group">
 <input id="chat_text" class="form-control" placeholder="Enter your message" name="chat_text"/>
 <span class="input-group-btn">
 <button type="submit" class="btn btn-primary" name="chat_message_send" id="chat_message_send">Send</button>

$('.chat').submit(function (e) {

 e.preventDefault(); // avoid to execute the actual submit of the form.

 var message = document.getElementById('chat_text').value; 

 type: "POST",
 url: hdir + "actions/responderActions.php",
 data: {
 'chat_message_send': 'yes'
 'chat_text': message
 success: function (response) {

 error: function (XMLHttpRequest, textStatus, errorThrown) {


PHP handler

chat_message_send function() {
 $chat_message_text = htmlspecialchars($_POST['chat_text']);


 $uid = $_SESSION['id'];

 $link = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);

 mysqli_set_charset($link, 'utf8');

 if (!$link) {
 die('Could not connect:' .mysql_error());

 $sql = "INSERT INTO chat (userId, chat_text) VALUES (?, ?)";

 try {
 $stmt = mysqli_prepare($link, $sql);
 mysqli_stmt_bind_param($stmt, "is", $uid, $chat_message_text);
 $result = mysqli_stmt_execute($stmt);

 if ($result == FALSE) {
 catch (Exception $e)
 die("Failed to run query:" . $e->getMessage()); //TODO: A function to send me an email when this occurs should be made


April 7th 20 at 11:57
0 answer

Find more questions by tags AJAXHTMLPHP