刷新div成功而不是使用Ajax刷新整个页面?

时间:2011-06-15 23:08:15

标签: jquery html refresh

如何只刷新成功的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);
            });
        }
    });
});

2 个答案:

答案 0 :(得分:2)

让我们假设div id是theDiv

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

答案 1 :(得分:1)

这里div类是要用msg <

替换的div的类名
    success: function (msg) {
      <br> $(.divclass).html(msg);
      <br>  });
    <br>}