【问题标题】:Refresh a div on success instead of refreshing the whole page using Ajax?成功刷新 div 而不是使用 Ajax 刷新整个页面?
【发布时间】:2011-06-15 23:08:15
【问题描述】:

如何在成功时只刷新一个 div 而不是使用 Ajax 刷新整个页面?

$('a.add-to-cart').click(function (e) {
    var url = "<?php echo createItemLink($row['id']);?>";
    e.preventDefault();
    $.ajax({
        type: 'post',
        url: "<?php echo SITEURL;?>/ajax/addtoCart.php",
        data: 'itemid=<?php echo $row['id'];?>&price=<?php echo $row['price'];?>&name=<?php echo $row['title'];?>',
        success: function (msg) {
            $("#status").fadeIn(300).delay(800).fadeOut(300).ajaxComplete(function (event, request, settings) {
                $(this).html(msg);
                $(location).attr('href',url);
            });
        }
    });
});

【问题讨论】:

    标签: jquery html refresh


    【解决方案1】:

    假设 div id 是 theDiv

    success: function (msg) {
        $("#status").fadeIn(300).delay(800).fadeOut(300).ajaxComplete(function (event, request, settings) {
            $('#theDiv').html(msg);
        });
    }
    

    【讨论】:

      【解决方案2】:

      这里的 div 类是要替换为 msg 的 div 的类名

          success: function (msg) {
            <br> $(.divclass).html(msg);
            <br>  });
          <br>}
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-06-18
        • 1970-01-01
        • 2011-12-22
        • 2014-03-23
        • 1970-01-01
        相关资源
        最近更新 更多