购物车只使用Jquery和Codeigniter更新一次
我正在使用Ajax调用来更新使用Jquery更新Codeigntier Cart。 这是我的jquery函数
$(function() { $('.cart_form select').on('change', function(ev) { var rowid = $(this).attr('class'); var qty = $(this).val(); var postData_updatecart = { 'rowid' : rowid, 'qty' : qty }; //posting data to update cart $.ajax({ url : base_url + 'bookings/update_booking_cart', type : 'post', data : postData_updatecart, beforeSend : function() { $('#cart_content').html('Updating...'); }, success : function(html) { //window.location.href = "postproperty.php?type="+suffix+'&page=page1'; $('#cart_content').html(html); } }); }); });
我有购物车视图文件
'bookings_form_customer', 'id' => 'bookings_form_customer')); ?> Item Description QTY Item Price Sub-Total cart->contents() as $items): ?> cart->has_options($items['rowid']) == TRUE): ?> cart->product_options($items['rowid']) as $option_name => $option_value): ?> :
<select name="" class=""> <?php for($tt=0; $tt <option value="" > cart->format_number($items['price']); ?> $cart->format_number($items['subtotal']); ?> Total $cart->format_number($this->cart->total()); ?>
事情很好。 但是,假设我有2个产品,如果我从1到2选择一个项目的数量,则更新购物车并使用AJAX显示更新的购物车。 但是,如果我立即更改另一个项目的数量,那么它不起作用。
购物车视图文件位于类’cart_form’中。
帮助的人表示赞赏。
我得到了答案。 您可以参考下面的链接Ajax请求只能工作一次
要么
直接按照这个
REPLACE jquery代码部分
$(function() { $(document).on( "change", "#bookings_form_customer select", function(ev) { // your code goes here }); });