duanmu6752 2013-07-19 08: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 08: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条)

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 R语言卸载之后无法重装,显示电脑存在下载某些较大二进制文件行为,怎么办
  • ¥15 java 的protected权限 ,问题在注释里