title: ckEditor and pediodic jQuery Ajax for multi editors
body: <p>I use inline edit feature of ckEditor and Ajax of jQuery (learnt from oleq) to illustrate the problem I have. It works fine if I just have one editor. The text is read from a file then by periodic ajax function text is written back to the file.
  The following code shows that.</p>
  
  <pre><code>&lt;?php
  if (!is_file('textFile.txt')) {
      file_put_contents('textFile.txt', 'This is the contents of file textFile.txt');
  }
  
  if (count($_POST)) {
      //retrieve data from POST write to the file
      if (isset($_POST['textFile'])) {
          file_put_contents('textFile.txt', $_POST['textFile']);
      }
      exit;
  }
  ?&gt; 
  
  &lt;script type="text/javascript" src="./css/jQuery.js"&gt;&lt;/script&gt;          
  &lt;script src="./ckeditor/ckeditor.js"&gt;&lt;/script&gt; 
  &lt;script&gt;
      // The "instanceCreated" event is fired for every editor
      CKEDITOR.on('instanceCreated', function(event) {
          var editor = event.editor,
              element = editor.element;
      });
  &lt;/script&gt;
  &lt;div id="container"&gt;
      &lt;p id="text" contenteditable="true"&gt;
          &lt;?php echo file_get_contents('textFile.txt'); ?&gt;
      &lt;/p&gt;
      &lt;script&gt;
          CKEDITOR.disableAutoInline = true;
          var editor = CKEDITOR.inline('text', { on: {
              instanceReady: function() {
                  periodicText();
              }
          }});
          CKEDITOR.disableAutoInline = false;
  
          var periodicText = (function() {
              var data, oldData;
              return function() {
                  if ((data = editor.getData()) !== oldData) {
                      oldData = data;
                      console.log(data);
                      $.post("help.php", { 
                              textFile:data
                          }
                      );
                  }
                  setTimeout(periodicText, 1000);
              };
          })();
      &lt;/script&gt;
  &lt;/div&gt;
  </code></pre>
  
  <h2>This second script I wrote for 2 editors and it does not work. Thanks in advance for telling me what did I do wrong. :)</h2>
  
  <pre><code>&lt;?php
      if (!is_file('textFile.txt')) {
          file_put_contents('textFile.txt', 'This is the contents of file textFile.txt');
      }
      if (!is_file('foxFile.txt')) {
          file_put_contents('foxFile.txt', 'The quick brown fox jumps over the lazy dog.');
      }
  
      if (count($_POST)) {
          //retrieve data from POST write to the file
          if (isset($_POST['textFile'])) {
              file_put_contents('textFile.txt', $_POST['textFile']);
          }
          if (isset($_POST['foxFile'])) {
              file_put_contents('foxFile.txt', $_POST['foxFile']);
          }
          exit;
      }
  ?&gt; 
  
  &lt;script type="text/javascript" src="./jQuery/jQuery.js"&gt;&lt;/script&gt;          
  &lt;script src="./ckeditor/ckeditor.js"&gt;&lt;/script&gt; 
  &lt;script&gt;
      // The "instanceCreated" event is fired for every editor
      CKEDITOR.on('instanceCreated', function(event) {
          var editor = event.editor,
              element = editor.element;
      });
  &lt;/script&gt;
  &lt;div id="container"&gt;
      &lt;p id="text" contenteditable="true"&gt;
          &lt;?php echo file_get_contents('textFile.txt'); ?&gt;
      &lt;/p&gt;
      &lt;script&gt;
          CKEDITOR.disableAutoInline = true;
          var editor = CKEDITOR.inline('text', { on: {
              instanceReady: function() {
                  periodicText();
              }
          }});
          CKEDITOR.disableAutoInline = false; 
  
          var periodicText = (function() {
              var data, oldData;
              return function() {
                  if ((data = editor.getData()) !== oldData) {
                      oldData = data;
                      console.log(data);
                      $.post("bar.php", { 
                              textFile:data
                          }
                      );
                  }
                  setTimeout(periodicText, 1000);
              };
          })();
      &lt;/script&gt;
      &lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;
      &lt;p id="text" contenteditable="true"&gt;
          &lt;?php echo file_get_contents('foxFile.txt'); ?&gt;
      &lt;/p&gt;
      &lt;script&gt;
          CKEDITOR.disableAutoInline = true;
          var editor = CKEDITOR.inline('text', { on: {
              instanceReady: function() {
                  periodicFox();
              }
          }});
          CKEDITOR.disableAutoInline = false; 
  
          var periodicFox = (function() {
              var data, oldData;
              return function() {
                  if ((data = editor.getData()) !== oldData) {
                      oldData = data;
                      console.log(data);
                      $.post("bar.php", { 
                              foxFile:data
                          }
                      );
                  }
                  setTimeout(periodicFox, 1000);
              };
          })();
      &lt;/script&gt;   
  &lt;/div&gt;
  </code></pre>