I know there are tons of questions like this one, but I still can't get this to work properly. Even a comment of what I should do to make this correct is more than enough since I understand like 80% of the jQuery..
<form action="meddelanden.php" id="fromen2" method="post">
<input type="text" name="message" id="type" autocomplete="off" placeholder="type your chat message">
<input class="lg" type="submit" name="submit" value="Send">
</form>
Meddelanden.php
<?php
session_start();
$meddelanden = $_POST['message'];
$username = $_SESSION['user'];
include ("connect.php");
$sql = $con->prepare('INSERT INTO messages (message,username) VALUES (?,?)');
$sql->bind_param("ss",$meddelanden,$username);
$sql->execute();
$sql->close();
$con->close();
?>
Scripts (which mess things up for my head)
$('#fromen2').submit(function(){
$.ajax({
type: 'POST',
url: meddelanded.php,
data: {
user: username, // <-- is this what i should write in data?!
message: message // <-- and this?!
},
success: function(msg){
alert('Message Sent');
}
});
return false;
});
So, my problem is what I should write in the data:
, and I have no clue what I'm supposed to type there! Can anybody help me, or is it something else that makes it not work?