title: how to reverse AJAX on HTML contenteditable DIV going to mySQL DB with PHP
body: <p>Below you will find a link to my contenteditable DIV page, appropriately titled ce.php:</p>
  
  <p><a href="http://stateofdebate.com/ce.php" rel="nofollow">http://stateofdebate.com/ce.php</a></p>
  
  <p>My desire from this question is to find an answer to how I can use Comet/reverse AJAX to immediately update the text on the page for all users when the text is changed. CURRENTLY, it is saved to my mySQL database, and the text is only updated when other users refresh the page.</p>
  
  <p>Please do not give vague answers like "use WebSocket" or "use node.js". I have asked a question already similar to this and gotten those kind of answers. To get a vote or check from me, I need either complete answers or links to tutorials.</p>
  
  <p>I feel like this, although a specific question with specific code, could help a lot of people with similar questions, if answered throughly and correctly.</p>
  
  <p>Here is my complete code:</p>
  
  <p>CE.PHP</p>
  
  <pre><code>&lt;!doctype html&gt;
  &lt;head&gt;
  
  &lt;meta charset="utf-8"&gt;
  &lt;title&gt;Gazpo.com - HTML5 Inline text editing and saving &lt;/title&gt;
  
  
  &lt;link href='http://fonts.googleapis.com/css?family=Droid+Serif' rel='stylesheet'      
  type='text/css'&gt;
  &lt;style&gt;
  body {      
  font-family: Helvetica,Arial,sans-serif;
  color:#333333;
  font-size:13px;
  }
  
  h1{
  font-family: 'Droid Serif', Georgia, Times, serif;
  font-size: 28px;        
  }
  
  a{
  color: #0071D8;
  text-decoration:none;
  }
  
  a:hover{
  text-decoration:underline;
  }
  
  :focus {
  outline: 0;
  }
  
  #wrap{
  width: 500px;
  margin:0 auto;              
  overflow:auto;      
  }
  
  #content{
  background: #f7f7f7;
  border-radius: 10px;
  }
  
  #editable {     
  padding: 10px;      
  }
  
  #status{
  display:none; 
  margin-bottom:15px; 
  padding:5px 10px; 
  border-radius:5px;
  }
  
  .success{
  background: #B6D96C;
  }
  
  .error{
  background: #ffc5cf; 
  }
  
  #footer{
  margin-top:15px;
  text-align: center;
  }
  
  #save{  
  display: none;
  margin: 5px 10px 10px;      
  outline: none;
  cursor: pointer;    
  text-align: center;
  text-decoration: none;
  font: 12px/100% Arial, Helvetica, sans-serif;
  font-weight:700;    
  padding: 5px 10px;  
  -webkit-border-radius: 5px; 
  -moz-border-radius: 5px;
  border-radius: 5px; 
  color: #606060;
  border: solid 1px #b7b7b7;  
  background: #fff;
  background: -webkit-gradient(linear, left top, left bottom, from(#fff), to(#ededed));
  background: -moz-linear-gradient(top,  #fff,  #ededed);
  filter:  progid:DXImageTransform.Microsoft.gradient(startColorstr='#ffffff',    
  endColorstr='#ededed');
  }   
  
  #save:hover
  {
  background: #ededed;
  background: -webkit-gradient(linear, left top, left bottom, from(#fff), to(#dcdcdc));
  background: -moz-linear-gradient(top,  #fff,  #dcdcdc);
  filter:  progid:DXImageTransform.Microsoft.gradient(startColorstr='#ffffff',   
  endColorstr='#dcdcdc');
  }
  
  &lt;/style&gt;
  
  &lt;script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"   
  type="text/javascript"&gt;&lt;/script&gt;
  &lt;script&gt;
  $(document).ready(function() {
  
  $("#save").click(function (e) {         
      var content = $('#editable').html();    
  
      $.ajax({
          url: 'save.php',
          type: 'POST',
          data: {
          content: content
          },              
          success:function (data) {
  
              if (data == '1')
              {
                  $("#status")
                  .addClass("success")
                  .html("Data saved successfully")
                  .fadeIn('fast')
                  .delay(3000)
                  .fadeOut('slow');   
              }
              else
              {
                  $("#status")
                  .addClass("error")
                  .html("An error occured, the data could not be saved")
                  .fadeIn('fast')
                  .delay(3000)
                  .fadeOut('slow');   
              }
          }
      });   
  
  });
  
  $("#editable").click(function (e) {
      $("#save").show();
      e.stopPropagation();
  });
  
  $(document).click(function() {
      $("#save").hide();  
  });
  
  });
  &lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;div id="wrap"&gt;
  &lt;h1&gt;&lt;a href="http://gazpo.com/2011/09/contenteditable/" &gt; HTML5 Inline text editing and   
  saving &lt;/a&gt;&lt;/h1&gt;
  
  &lt;h4&gt;The demo to edit the data with html5 &lt;i&gt;contentEditable&lt;/i&gt;, and saving the changes   
  to database with PHP and jQuery.&lt;/h4&gt;
  
  &lt;div id="status"&gt;&lt;/div&gt;
  
  &lt;div id="content"&gt;
  
  &lt;div id="editable" contentEditable="true"&gt;
  &lt;?php
      //get data from database.
      include("db.php");
      $sql = mysql_query("select text from content where element_id='1'");
      $row = mysql_fetch_array($sql);         
      echo $row['text'];
  ?&gt;      
  &lt;/div&gt;  
  
  &lt;button id="save"&gt;Save&lt;/button&gt;
  &lt;/div&gt;
  
  &lt;div id="footer"&gt;
  &lt;a href="http://gazpo.com/"&gt;Tutorial by gazpo.com&lt;/a&gt; 
  &lt;/div&gt;
  &lt;/div&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>SAVE.PHP</p>
  
  <pre><code>&lt;?php
  include("db.php");
  $content = $_POST['content']; //get posted data
  $content = mysql_real_escape_string($content);  //escape string 
  $sql = "UPDATE content SET text = '$content' WHERE element_id = '1' ";
  if (mysql_query($sql))
  {
  echo 1;
  }
  ?&gt;
  </code></pre>
  
  <p>DB.PHP</p>
  
  <pre><code>&lt;?php
  //database connection
  mysql_connect("test.test00.com:2400", "first_testuser", "pw") or die(mysql_error());
  mysql_select_db("jorgea_testdb") or die(mysql_error());
  ?&gt;
  </code></pre>
  
  <p>EDIT: still looking for an answer!
  EDIT: deleting old question and creating new one in attempt to find someone who can answer this....</p>