How can I update the DOM with new record added element after call?
Should I return the newly inserted db record contents on call back then append using jquery?
Please advice if not enough data to answer question.
$(function(){
$('#postentry').submit(function() {
var tyu = $('#tittle_ent').val();
if(tyu.length <= 2)
{alert('Enter More Text!'); return false;}else
{
$.post(
"posts_in.php",
$("#postentry").serialize(),
function(data){
//alert(data);
}
);
return false;
}
});
});
Each record look like this:
<div id="post349" class="myclass">
This is some text.
</div>
I'd use $.ajax()
instead of $.post()
:
$.ajax({
type:'post',
url: 'posts_in.php',
data: $("#postentry").serialize(),
success:function(data){
var id='post349';
$('<div></div>').attr('id',id).addClass('myclass').html(data).appendTo('#records_wrapper');
}
});
Quick demo of how the div will be appended and populated: http://jsfiddle.net/AlienWebguy/zuPA2/1/
You can either return a complete record in the surrounding div
from php or you can just get the newly inserted ID and build the record in javascript.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With