Cod*_*x73 6 javascript php ajax jquery
如何在调用后使用新记录添加元素更新DOM?
我应该在回调时返回新插入的db记录内容,然后使用jquery追加吗?
如果没有足够的数据来回答问题,请建议.
$(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;
}
});
});
Run Code Online (Sandbox Code Playgroud)
每个记录看起来像这样:
<div id="post349" class="myclass">
This is some text.
</div>
Run Code Online (Sandbox Code Playgroud)
我会使用$.ajax()而不是$.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');
}
});
Run Code Online (Sandbox Code Playgroud)
如何附加和填充 div 的快速演示:http://jsfiddle.net/AlienWebguy/zuPA2/1/
| 归档时间: |
|
| 查看次数: |
6549 次 |
| 最近记录: |