这是Ajax Call
<script type="text/javascript">
function update()
{
var quantity = $("#update_quantity").val();
var o_id = $("#update_order_id").val();
$.ajax({
url: '<?php echo base_url();?>index.php/dealers/cart/update_cart',
data: {"quantity":quantity, "order_id":o_id},
type: 'post',
success: function(msg){
alert(msg);
}
});
}
</script>
控制器代码是
function update_cart(){
$o_id = $this->input->post('order_id');
$quantity = $this->input->post('quantity');
$this->db->where('order_id' ,$o_id);
$update['quantity'] = $quantity;
$this->db->update('orders', $update);
$sql = "SELECT quantity, price, (quantity * price) AS Total FROM orders WHERE order_id =". $o_id;
$execute = mysql_query($sql);
if(mysql_num_rows($execute) > 0){
$result = mysql_fetch_array($execute);
$total = $result['Total'];
}
$this->db->where('order_id' ,$o_id);
$update_price['total_price'] = $total;
$this->db->update('orders', $update_price);
echo "Cart Updated";
}
当我更新数量,最高项目的数量更新但是当我使用上述Ajax代码更新项目的数量而不是顶级项目时,它未更新
我该如何解决这个问题 我想在更新任何项目的数量时,应该使用ajax调用更新