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>
</span>
</div>
</form>


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

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

 var message = document.getElementById('chat_text').value; 
$('#chat_text').val(");


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

},
 error: function (XMLHttpRequest, textStatus, errorThrown) {
console.log("Error");
}

});
 });


PHP handler

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

session_start();

 $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) {
die(mysqli_error($link));
}
}
 catch (Exception $e)
{
 die("Failed to run query:" . $e->getMessage()); //TODO: A function to send me an email when this occurs should be made
}

mysqli_close($link);

}
April 7th 20 at 11:57
0 answer

Find more questions by tags AJAXHTMLPHP