
Untitled
By: a guest on
May 8th, 2012 | syntax:
None | size: 2.17 KB | hits: 10 | expires: Never
after inline edit new text does not appear
$(document).ready(function(){
$counter = 0;
$.ajaxSetup({
url: 'save.php',
type: 'POST',
async: false,
timeout: 500
});
$(".editme2").inlineEdit({
control: 'textarea',
value: $.ajax({ data: { 'action': 'get' } }).responseText,
save: function(event, data) {
var html = $.ajax({
data: { 'action': 'save', 'value': data.value }}).responseText;
alert("id: " + this.id );
return html === 'OK' ? true : false;
}
});
$("#hide").click(function(){
if ($counter < 10)
{ $counter++;
$('#container').show( );
$('#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>');
$( '.inside' ).draggable({ containment: '#there' });
}
});
;
});
</script>
<?php
if(isset($_POST['value']) && isset($_POST['action']) ){
$action = isset($_POST) && $_POST['action'] ? $_POST['action'] : 'get';
$value = isset($_POST) && $_POST['value'] ? $_POST['value'] : '';
session_start();
$data = isset($_SESSION) && $_SESSION['data'] ? $_SESSION['data'] : 'Hello World!';
switch ($action) {
// retrieve data
case 'get':
echo file_get_contents('data.txt');
//echo $data;
break;
// save data
case 'save':
if ($value != '') {
$fp = fopen('data.txt','w');
fwrite($fp, $value);
fclose($fp);
$_SESSION['data'] = $value;
echo "OK";
} else {
echo "ERROR: no value received.";
}
break;
// no action
default:
echo "ERROR: no action specified.";
break;
}
}