title: autoSave on LAST KeyUp ONLY JQuery, PHP, MySQL. How?
body: <p>Here's some code I've found that I think is the key to my answer but I haven't been able to fully understand it yet.</p>
  
  <p><a href="https://github.com/geniuscarrier/autoSave/blob/master/jquery.autoSave.js" rel="nofollow noreferrer">jQuery autoSave v1.0.0</a></p>
  
  <pre><code>/*
   jQuery autoSave v1.0.0 - 2013-04-05
   (c) 2013 Yang Zhao - geniuscarrier.com
   license: http://www.opensource.org/licenses/mit-license.php
   */
  (function($) {
      $.fn.autoSave = function(callback, ms) {
          return this.each(function() {
              var timer = 0, 
                  $this = $(this),
                  delay = ms || 1000;
              $this.keyup(function() {
                  clearTimeout(timer);
                  var $context = $this.val();
                  if(localStorage) {
                      localStorage.setItem("autoSave", $context);
                  }
                  timer = setTimeout(function() {
                      callback();
                  }, delay);
              });
          });
      };
  })(jQuery);
  </code></pre>
  
  <p>Below I have a working sample of what I've researched so far. I want to modify this code so that it triggers on KeyUp instead of simply every so many seconds regardless of user updating or not.</p>
  
  <p><strong>index.php</strong></p>
  
  <pre><code>&lt;html&gt;
  
  &lt;head&gt;
    &lt;meta name="viewport" content="initial-scale=1.0, user-scalable=no"&gt;
    &lt;meta charset="utf-8"&gt;
    &lt;title&gt;Webslesson Tutorial&lt;/title&gt;
    &lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"&gt;&lt;/script&gt;
    &lt;link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css"&gt;
    &lt;script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"&gt;&lt;/script&gt;
  &lt;/head&gt;
  
  &lt;body&gt;
    &lt;div class="container"&gt;
      &lt;br&gt;
      &lt;h2 align="center"&gt;Auto Save Data using Ajax, Jquery, PHP and Mysql&lt;/h2&gt;
      &lt;br&gt;
      &lt;div class="form-group"&gt; &lt;label&gt;Enter Post Title&lt;/label&gt;
        &lt;input type="text" name="post_title" id="post_title" class="form-control"&gt; &lt;/div&gt;
      &lt;div class="form-group"&gt; &lt;label&gt;Enter Post Description&lt;/label&gt; &lt;textarea name="post_description" id="post_description" rows="6" class="form-control"&gt;&lt;/textarea&gt; &lt;/div&gt;
      &lt;div class="form-group"&gt;
        &lt;button type="button" name="publish" class="btn btn-info"&gt;Publish&lt;/button&gt;
      &lt;/div&gt;
      &lt;div class="form-group"&gt;
        &lt;input type="hidden" name="post_id" id="post_id"&gt;
        &lt;div id="autoSave"&gt;&lt;/div&gt;
      &lt;/div&gt;
    &lt;/div&gt;
    &lt;script&gt;
      $(document).ready(function(){  
            function autoSave()  
            {  
                 var post_title = $('#post_title').val();  
                 var post_description = $('#post_description').val();  
                 var post_id = $('#post_id').val();  
                 if(post_title != '' &amp;&amp; post_description != '')  
                 {  
                      $.ajax({  
                           url:"save_post.php",  
                           method:"POST",  
                           data:{postTitle:post_title, postDescription:post_description, postId:post_id},  
                           dataType:"text",  
                           success:function(data)  
                           {  
                                if(data != '')  
                                {  
                                     $('#post_id').val(data);  
                                }  
                                $('#autoSave').text("Post save as draft");  
                                setTimeout(function(){  
                                     $('#autoSave').text('');  
                                }, 5000);  
                           }  
                      });  
                 }            
            }  
            setInterval(function(){   
                 autoSave();   
                 }, 10000);  
       });
    &lt;/script&gt;
  &lt;/body&gt;
  
  &lt;/html&gt;
  </code></pre>
  
  <p><strong>save_post.php</strong></p>
  
  <pre><code>&lt;?php  
   $connect = mysqli_connect("mysqlserver", "database", "password", "databasename");
   if(isset($_POST["postTitle"]) &amp;&amp; isset($_POST["postDescription"]))
   {
    $post_title = mysqli_real_escape_string($connect, $_POST["postTitle"]);
    $post_description = mysqli_real_escape_string($connect, $_POST["postDescription"]);
    if($_POST["postId"] != '')  
    {  
      //update post  
      $sql = "UPDATE tbl_post SET post_title = '".$post_title."', post_description = '".$post_description."' WHERE post_id = '".$_POST["postId"]."'";  
      mysqli_query($connect, $sql);  
    }  
    else  
    {  
      //insert post  
      $sql = "INSERT INTO tbl_post(post_title, post_description, post_status) VALUES ('".$post_title."', '".$post_description."', 'draft')";  
      mysqli_query($connect, $sql);  
      echo mysqli_insert_id($connect);  
    }
   }  
  ?&gt;
  </code></pre>