Refresh a div on success instead of refreshing the whole page using Ajax?
How can I refresh only a div on success instead of refreshing the whole page using 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'];?>',
开发者_JAVA百科 success: function (msg) {
$("#status").fadeIn(300).delay(800).fadeOut(300).ajaxComplete(function (event, request, settings) {
$(this).html(msg);
$(location).attr('href',url);
});
}
});
});
let's assume div id's is theDiv
success: function (msg) {
$("#status").fadeIn(300).delay(800).fadeOut(300).ajaxComplete(function (event, request, settings) {
$('#theDiv').html(msg);
});
}
here div class is class name of div which you want to replace with msg
success: function (msg) {
<br> $(.divclass).html(msg);
<br> });
<br>}
精彩评论