I am on this practice project of developing a login and sign up system of a Secret Diary. Everything else is working as it should and fine but I am stuck at this one part. Actually in the secret diary is a textarea and I am trying to make it so that whenever a change takes place in textarea, AJAX passes the data to a php file and php should update the database.
$("textarea").on("input propertychange", function() {
$.ajax({
method: "POST",
url: "updatediary.php",
data: {
content: $("textarea").val()
}
});
});
<?php
session_start();
$link = mysqli_connect("localhost", "cl44-secretdr", "********", "cl44-secretdr");
if (mysqli_connect_error())
{
die ("Database Connection Error");
}
if (isset($_POST['content']))
{
$query = "UPDATE `users` SET `diary` = '".$_POST['content']."' WHERE id = '".$_SESSION['id']."'";
$result = mysqli_query($link, $query);
}
?>
Help me out please!
What version of jQuery are you using? Before the 1.9 version the "method" attribute of the ajax request is called "type". Maybe if you change that attribute it will work.