2011-06-15 129 views
0

我怎樣才能刷新成功的div而不是使用Ajax刷新整個頁面?刷新成功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

假設DIV的id是theDiv

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

看起來更換喜歡你解決了它的div的類名!你真棒謝謝! – JonnyPlow 2011-06-16 00:43:42

1

這裏的div類是你想用味精

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