Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 8th, 2012  |  syntax: None  |  size: 2.17 KB  |  hits: 10  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. after inline edit new text does not appear
  2. $(document).ready(function(){
  3.                 $counter = 0;
  4.  
  5.                    $.ajaxSetup({
  6.                       url: 'save.php',
  7.                       type: 'POST',
  8.                       async: false,
  9.                       timeout: 500
  10.                   });
  11.  
  12.                   $(".editme2").inlineEdit({
  13.                   control: 'textarea',
  14.                   value: $.ajax({ data: { 'action': 'get' } }).responseText,
  15.                   save: function(event, data) {
  16.                         var html = $.ajax({
  17.                             data: { 'action': 'save', 'value': data.value }}).responseText;
  18.  
  19.                             alert("id: " + this.id );
  20.  
  21.                             return html === 'OK' ? true : false;
  22.                             }
  23.                   });
  24.  
  25.                   $("#hide").click(function(){
  26.                         if ($counter < 10)
  27.                         { $counter++;
  28.  
  29.                           $('#container').show( );
  30.                           $('#container').append( '<div class="inside" style="background: yellow; width: 400px;"><p class="editme2" id="edited'+$counter+'">Click me to add text and drag me to where you want me to be</p></div>');
  31.                           $( '.inside' ).draggable({ containment: '#there' });
  32.                            }
  33.                                   });
  34.                   ;
  35.      });
  36.     </script>
  37.        
  38. <?php
  39.  
  40.   if(isset($_POST['value']) && isset($_POST['action']) ){
  41.   $action = isset($_POST) && $_POST['action'] ? $_POST['action'] : 'get';
  42.   $value  = isset($_POST) && $_POST['value'] ? $_POST['value'] : '';
  43.  
  44.   session_start();
  45.   $data = isset($_SESSION) && $_SESSION['data'] ? $_SESSION['data'] : 'Hello World!';
  46.  
  47.   switch ($action) {
  48.  
  49. // retrieve data
  50.   case 'get':
  51.      echo file_get_contents('data.txt');
  52.      //echo $data;
  53.      break;
  54.  
  55. // save data
  56.    case 'save':
  57.     if ($value != '') {
  58.         $fp = fopen('data.txt','w');
  59.         fwrite($fp, $value);
  60.         fclose($fp);
  61.         $_SESSION['data'] = $value;
  62.         echo "OK";
  63.      } else {
  64.         echo "ERROR: no value received.";
  65.      }
  66.      break;
  67.  
  68.   // no action
  69.   default:
  70.     echo "ERROR: no action specified.";
  71.     break;
  72.  }
  73. }