dsgd4654674 2014-05-23 23:36 采纳率: 0%
浏览 575

在AJAX成功之后隐藏div

Im using the following AJAX call to update a record in my table:

$(function() {
    $(".decline").click(function(){
        var element = $(this);
        var del_id = element.attr("id1");
        var order_id = element.attr("data-order1");
        $.ajax({
            type: "POST",
            url: "decline.php",
            data: {id1:del_id,order_id1:order_id},
            success: function(){cache: false}
        });
        $(this).parents(".show").animate({ backgroundColor: "#003" }, "slow")
            .animate({ opacity: "hide" }, "slow");
    });
});

It animates the div as required when zi click on the selector class .decline here:

<div class="<?php echo ($accept == '1')?'showop':'show';?>">
<span class="growthcust">$<?php echo number_format($growth);  ?></span>
<span class="accepted"><a href="#" class="accept" id="<?php echo $id1; ?>" data-order="<?php echo $name; ?>"><input type="button" title="accept" value="Accept" /></a></span>
<span><a href="#"  class="decline"   id1="<?php echo $id1; ?>" data-order1="<?php echo $name; ?>"><input type="button" title="declined" value="Decline" /></a></span>
</div>

but Id like to move the function to my AJAX call so the div hides after the AJAX call succeeds.

How would I change it to animate upon success?

  • 写回答

1条回答 默认 最新

  • doubi6303 2014-05-23 23:42
    关注

    Run the hiding code in the success callback. You can access the current element using the element variable that you bound.

    $(function() {
        $(".decline").click(function(){
            var element = $(this);
            var del_id = element.attr("id1");
            var order_id = element.attr("data-order1");
            $.ajax({
                type: "POST",
                url: "decline.php",
                data: {id1:del_id,order_id1:order_id},
                // cache: false, // Not needed for POST, they're never cached
                success: function(){
                    element.parents(".show").animate({ backgroundColor: "#003" }, "slow")
                        .animate({ opacity: "hide" }, "slow");
                }
            });
        });
    });
    
    评论

报告相同问题?

悬赏问题

  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 关于无人驾驶的航向角
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥30 BC260Y用MQTT向阿里云发布主题消息一直错误
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了