jQuery:在另一个jquery操作之后刷新div? [英] jQuery: Refresh div after another jquery action?

查看:85
本文介绍了jQuery:在另一个jquery操作之后刷新div?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在另一个jquery动作之后刷新元素(div,类等)?

How do I refresh element (div, class whatever) after another jquery action?

我有此操作正在从数据库中删除一条记录,并且我需要刷新div,该div也正在从数据库中获取其他一些数据...

I have this action which is deleting a record from database and I need to refresh div which is fetching some other data from database as well...

下面是代码:

$(function() {
    $(".delete").click(function() {
        var commentContainer = $(this).parent();
        var id = $(this).attr("id");
        var string = 'id='+ id ;

        $.ajax({
           type: "POST",
           url: "delete.php",
           data: string,
           cache: false,
           success: function(){
               commentContainer.slideUp('slow', function() {$(this).remove();});
           }
         });

        return false;
    });
});

感谢所有帮助! :)

推荐答案

在AJAX调用期间,可以使用成功函数在成功调用之后运行命令.您的代码中已经有一个函数,因此只需简单地更新该函数即可.您要更新的第二个div也可以使用AJAX加载.

During an AJAX call you can use the success function to run commands after a successful call. You already have a function in your code so its a simple matter of updating that function. The second div that you will like to update can be loaded with AJAX too.

 $.ajax({
  //other options
  success:function(){
       commentContainer.slideUp('slow', function() {$(this).remove();});
       $('#otherdiv').load('urlofpagewith info.php');
  }

 });

这篇关于jQuery:在另一个jquery操作之后刷新div?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆