I want to update two divs with one ajax request only. However following code clears out both the divisions without updating the data. Please have a look at my code:
AJAX Request File
<div class='subtotal_<?php echo $row['productid']; ?>'>
<p>Subtotal: <?php echo $subtotal; ?></p>
</div>
<div id='totalamount'>
<p>Totalamount: <?php echo round($total); ?></p>
</div>
var productid = $(this).attr('class');
$.ajax
({
type: "POST",
url: "ajax_changequantity.php",
data: {type:type,quantity:quantity,productid:productid},
success: function(option)
{
var html = $(option);
$('#totalamount').empty();
$('.subtotal_'+productid).replaceWith(("#subtotal",html));
$('#totalamount').replaceWith(("#totalamount",html));
}
});
Ajax File
<div id='subtotal'>
<p>Subtotal: <?php echo $subtotal; ?></p>
</div>
<div id='totalamount'>
<p>Total Amount: <?php echo $totalamount; ?></p>
</div>
Both the divs after successful ajax request get blank. No data coming in. Can anyone help finding the mistake here?