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条)

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度