duanmu6752 2013-07-19 00:01 采纳率: 0%
浏览 55
已采纳

将数据加载到当前div中

I have two divs, and when one is clicked it empties the div. I want to be able to load data into that div once it's been emptied. I've got it so it loads in both, but I only want to load data into the div that's been emptied.

HTML (I have two of these)

<div class="fl person">
    <div class="maintain_size">
        <input type="hidden" name="userSaved" value="<?php echo $user_one['id']; ?>" />
            <img src="<?php echo "http://graph.facebook.com/".$user_one['id']."/picture?type=large"; ?>" class="circle-mask"  />
            <img class="hoverimage" src="images/fire_extinguisher.png" />
            <div class="meta_data">
                <h2><?php echo $user_one['name']; ?></h2>
            </div>
    </div>
</div>

Javascript

<script>
$("div.person img").click(function () {
        $(this).parent("div").fadeOut(1000, function () {
        var saved_id_user_who_voted_val = "<?php echo $_SESSION['id']; ?>";
        var saved_id_user_voted_on_val = $(this).parent('div').find('input:hidden');
        var saved_id_user_voted_on_val = saved_id_user_voted_on_val.val();

        $(this).parent("div").empty();

        // Load in new data
        var current_div = $(this).parent("div");
        $.get('loadNewUser.php', function(data) {
          current_div.html(data);
        });
    });
});
</script>

The data seems to come through fine if I select a div that's not the current one, or I just use an alert to see if the data is there--which it is, but if I try load the data into the current div it just doesn't work. Any ideas? Thanks.

The code that I think is wrong:

$.get('loadNewUser.php', function(data) {
      current_div.html(data);
});

Edit: The div I'm trying to get the data into is: div.person - although, there are 2 of these.

展开全部

  • 写回答

3条回答 默认 最新

  • doutale7115 2013-07-19 00:17
    关注

    Once you empty the div your 'this' is no longer there. Try just declaring var current_div before you empty.

    var current_div = $(this).parent("div");
    current_div.empty();
    $.get('loadNewUser.php', function(data) {
          current_div.html(data);
    });
    

    See fiddle

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部