Note that there are some explanatory texts on larger screens.

plurals
  1. POCart is updated only once using Jquery and Codeigniter
    primarykey
    data
    text
    <p>I am working on Updating Codeigntier Cart with Jquery using Ajax call to update. Here is my jquery function</p> <pre><code>$(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+'&amp;page=page1'; $('#cart_content').html(html); } }); }); }); </code></pre> <p>I have cart view file as</p> <pre><code>&lt;div class="cart_form"&gt; &lt;?php echo form_open(base_url().'index.php/bookings/customerdetails', array('class' =&gt; 'bookings_form_customer', 'id' =&gt; 'bookings_form_customer')); ?&gt; &lt;table cellpadding="6" cellspacing="1" style="width:100%" border="0"&gt; &lt;tr&gt; &lt;th style="text-align:left"&gt;Item Description&lt;/th&gt; &lt;th style="text-align:left"&gt;QTY&lt;/th&gt; &lt;th style="text-align:right"&gt;Item Price&lt;/th&gt; &lt;th style="text-align:right"&gt;Sub-Total&lt;/th&gt; &lt;/tr&gt; &lt;?php $i = 1; ?&gt; &lt;?php foreach ($this-&gt;cart-&gt;contents() as $items): ?&gt; &lt;?php echo form_hidden($i.'[rowid]', $items['rowid']); ?&gt; &lt;tr&gt; &lt;td&gt; &lt;?php echo $items['name']; ?&gt; &lt;?php if ($this-&gt;cart-&gt;has_options($items['rowid']) == TRUE): ?&gt; &lt;p&gt; &lt;?php foreach ($this-&gt;cart-&gt;product_options($items['rowid']) as $option_name =&gt; $option_value): ?&gt; &lt;strong&gt;&lt;?php echo $option_name; ?&gt;:&lt;/strong&gt; &lt;?php echo $option_value; ?&gt;&lt;br /&gt; &lt;?php endforeach; ?&gt; &lt;/p&gt; &lt;?php endif; ?&gt; &lt;/td&gt; &lt;td&gt; &lt;select name="&lt;?php echo $i.'[qty]'; ?&gt;" class="&lt;?php echo $items['rowid']; ?&gt;"&gt; &lt;?php for($tt=0; $tt&lt;=10; $tt++) { ?&gt; &lt;option value="&lt;?php echo $tt; ?&gt;" &lt;?php if($tt==$items['qty']) echo 'selected="selected"'; ?&gt;&gt;&lt;?php echo $tt; ?&gt;&lt;/option&gt; &lt;?php } ?&gt; &lt;/select&gt; &lt;/td&gt; &lt;td style="text-align:right"&gt;&lt;?php echo $this-&gt;cart-&gt;format_number($items['price']); ?&gt;&lt;/td&gt; &lt;td style="text-align:right"&gt;$&lt;?php echo $this-&gt;cart-&gt;format_number($items['subtotal']); ?&gt;&lt;/td&gt; &lt;/tr&gt; &lt;?php $i++; ?&gt; &lt;?php endforeach; ?&gt; &lt;tr&gt; &lt;td colspan="2"&gt; &lt;/td&gt; &lt;td class="right"&gt;&lt;strong&gt;Total&lt;/strong&gt;&lt;/td&gt; &lt;td class="right"&gt;$&lt;?php echo $this-&gt;cart-&gt;format_number($this-&gt;cart-&gt;total()); ?&gt;&lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;p&gt;&lt;?php echo form_submit('update_cart', 'Update your Cart'); ?&gt;&lt;/p&gt; &lt;/form&gt; &lt;/div&gt; </code></pre> <p>Things are working Nice. But, lets say if I have 2 products, if i select one item's qty from 1 to 2, cart is updated and updated cart is shown using AJAX. But, if I immediately change another item's qty then it doesnt work. </p> <p>The cart view file is inside class 'cart_form'.</p> <p>Helping hands are appreciated.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload