Try to search your question here, if you can't find : Ask Any Question Now ?

Ajax post not working with Contenteditable

HomeCategory: stackoverflowAjax post not working with Contenteditable
bhawya asked 2 weeks ago

I have successfully created a <textarea> that posts content to the database without a need for button or page refresh. However, for design purposes I would like to use an editable <div>. So I’ve used contenteditable="true". However, the ajax post no longer works with <div>.

My Code:

$(document).ready(function() {
  var timer;
  $('#about').on('input', function() {
    var value = this.value;
    clearTimeout(timer);
    timer = setTimeout(function() {
      var about = $('#about').val().trim();
      $.ajax({
        url: "comment.php?customer_id=" + "<?php echo $customer_id; ?>",
        type: 'post',
        data: {
          about: about
        },
        success: function(response) {
          $('#cid').val(response);
        }
      });
    }, 2000);
  });
});
/* This is comment.php */

<?php
session_start();
require_once 'config/config.php';
require_once 'includes/auth_validate.php';

$cid = $_GET['customer_id'];
$about = $_POST['about'];

$sql = ("UPDATE patient_id SET about = ? WHERE id = ?;");

$stmt = mysqli_stmt_init($conn);
mysqli_stmt_prepare($stmt, $sql);
mysqli_stmt_bind_param($stmt, "si", $about, $cid);
mysqli_stmt_execute($stmt);
?>

Textarea

<div id="about" type="text" name="about" class="content livecomments" contenteditable="true" onpaste="OnPaste_StripFormatting(this, event);"><?php echo $edit ? ( empty( htmlentities ($row[ 'about' ]) ) ) ? 'test' : htmlentities ($row[ 'about' ]) : '';?></div>
1 Answers
Best Answer
Jyoti answered 2 weeks ago
Your Answer

4 + 13 =

Popular Tags

WP Facebook Auto Publish Powered By : XYZScripts.com