gpt4 book ai didi

javascript - 购物车仅使用 Jquery 和 Codeigniter 更新一次

转载 作者:行者123 更新时间:2023-11-28 01:42:21 24 4
gpt4 key购买 nike

我正在使用 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);

}
});

});

});

我的购物车 View 文件为

<div class="cart_form">
<?php echo form_open(base_url().'index.php/bookings/customerdetails', array('class' => 'bookings_form_customer', 'id' => 'bookings_form_customer')); ?>

<table cellpadding="6" cellspacing="1" style="width:100%" border="0">

<tr>
<th style="text-align:left">Item Description</th>
<th style="text-align:left">QTY</th>
<th style="text-align:right">Item Price</th>
<th style="text-align:right">Sub-Total</th>
</tr>

<?php $i = 1; ?>

<?php foreach ($this->cart->contents() as $items): ?>

<?php echo form_hidden($i.'[rowid]', $items['rowid']); ?>

<tr>
<td>

<?php echo $items['name']; ?>

<?php if ($this->cart->has_options($items['rowid']) == TRUE): ?>

<p>
<?php foreach ($this->cart->product_options($items['rowid']) as $option_name => $option_value): ?>

<strong><?php echo $option_name; ?>:</strong> <?php echo $option_value; ?><br />

<?php endforeach; ?>
</p>

<?php endif; ?>

</td>
<td>



<select name="<?php echo $i.'[qty]'; ?>" class="<?php echo $items['rowid']; ?>">

<?php
for($tt=0; $tt<=10; $tt++)
{
?>


<option value="<?php echo $tt; ?>" <?php if($tt==$items['qty']) echo 'selected="selected"'; ?>><?php echo $tt; ?></option>

<?php
}
?>
</select>

</td>



<td style="text-align:right"><?php echo $this->cart->format_number($items['price']); ?></td>
<td style="text-align:right">$<?php echo $this->cart->format_number($items['subtotal']); ?></td>
</tr>

<?php $i++; ?>

<?php endforeach; ?>




<tr>
<td colspan="2"> </td>
<td class="right"><strong>Total</strong></td>
<td class="right">$<?php echo $this->cart->format_number($this->cart->total()); ?></td>
</tr>

</table>

<p><?php echo form_submit('update_cart', 'Update your Cart'); ?></p>

</form>
</div>

一切进展顺利。但是,假设我有 2 件产品,如果我从 1 到 2 中选择一件商品的数量,则购物车会更新,并且使用 AJAX 显示更新的购物车。但是,如果我立即更改另一个项目的数量,那么它就不起作用。

购物车 View 文件位于类“cart_form”内。

感谢伸出援助之手。

最佳答案

我得到了答案。您可以引用下面的链接 Ajax Request works only once

或者

直接关注

替换 jquery 代码部分

$(function() {   
$(document).on( "change", "#bookings_form_customer select", function(ev) {
// your code goes here
});
});

关于javascript - 购物车仅使用 Jquery 和 Codeigniter 更新一次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20755982/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com