jQuery:通过ajax加载的内容可以更新DOM吗?

时间:2010-08-28 16:49:30

标签: jquery ajax dom

我有一个使用ajax加载到我页面上的帖子列表:

var fm = <?php echo $from_user ;?>;

$("#microblogposts").load("posts.php", {from_user: fm}, function(){
});

在这个帖子列表中,我有一个从列表中删除帖子的功能:

    //START POST DELETE FUNCTION    
$("form#deletepost").submit(function() {

// we want to store the values from the form input box, then send via ajax below
var deleteid = $('#deleteid').attr('value');

//START AJAX    
$.ajax({
    type : "POST",
    url: "process.php",
    data: {deleteid : deleteid},
    error: function(){ 
    alert("Mesage could not be posted at this time. Please try again.");
    },
    success: function(){ 

            $("#microblogposts").load("posts.php", {from_user: fm}, function(){
            //alert("posts have been loaded");
            });

            $("#latestpost").load("latestpost.php", {from_user: fm}, function(){
            //alert("latest posts have been loaded");
            });

    }
    //END SUCCESS FUNCTION
});
return false;
//END AJAX  

}); 
//END POST DELETE FUNCTION  

我希望代码在AJAX成功时刷新DOM中的一些元素,但它不起作用,无论如何可以做到这一点???

1 个答案:

答案 0 :(得分:1)

感谢jigfox的帮助。问题在于变量,它们都是空的,因此内容没有加载。