The following code works properly and I am using it 'cause I need to update some notes in DB without refreshing a page. But what have to do when I need in the same event get some data back?
index.php where change should occur
<?php
$s = $GET['...']
$p = $GET['...']
print '
<form id="notesForm">
<textarea name="c">'.$note.'</textarea>
<input type="text" value="LAST_CHANGE_NEED_GIVE_BACK_FROM_DB">
<input type="hidden" name="s" value="'.$s.'">
<input type="hidden" name="p" value="'.$p.'">
<input type="submit" value="save note">
<div id="response"></div>
</form>
';
?>
script which is posting data to live_notes.php and probably should be changed because of the goal
$(document).ready(function(){
$('#notesForm').submit(function(){
event.preventDefault();
$('#response').html("<b>saving...</b>");
$.ajax({
type: 'POST',
url: 'notes/live_notes.php',
data: $(this).serialize()
})
.done(function(data){
$('#response').html(data);
})
.fail(function() {
alert("bad luck");
});
return false;
});
});
notes/live_notes.php
<?php
$s = $_POST['s'];
$p = $_POST['p'];
$c = $_POST['c'];
// connecting DB
mysql_query("
UPDATE `poznamky`
SET
last_change = now(),
page = '$p',
content = '$c'
WHERE
page = '$p';
");
any idea?