Note that there are some explanatory texts on larger screens.

plurals
  1. POjQuery update does not work with IE7/8
    primarykey
    data
    text
    <p>With <a href="https://stackoverflow.com/questions/1683480/changing-from-prototype-to-jquery/1688508#1688508">the help of members from this post</a>, I converted from prototype to jQuery.</p> <pre><code>function jsUpdateCart(){ var parameter_string = ''; allNodes = document.getElementsByClassName("process"); for(i = 0; i &lt; allNodes.length; i++) { var tempid = allNodes[i].id; var temp = new Array; temp = tempid.split("_"); var real_id = temp[2]; var real_value = allNodes[i].value; parameter_string += real_id +':'+real_value+','; } var params = 'ids='+parameter_string; $.ajax({ type: "POST", url: "http://127.0.0.1/codeigniter_shopping/index.php/welcome/ajax_cart", data: params, success: function( r ) { $('#ajax_msg').html( r ); location.reload( true ); } }); } function jsRemoveProduct(id){ var params = 'id='+id; $.ajax({ type: "POST", url: "http://127.0.0.1/codeigniter_shopping/index.php/welcome/ajax_cart_remove", data: params, success: function( r ) { $('#ajax_msg').html( r ); location.reload( true ); } }); } </code></pre> <p>ajax_cart_remove works in both Firefox and IE, but update works with Firefox, but it doesn't with IE 7/8.</p> <p>Could anyone give me some suggestions please.</p> <p>You can see the original <a href="https://stackoverflow.com/questions/1683480/changing-from-prototype-to-jquery/1688508#1688508">prototype code here</a>.</p> <p>ajax_cart and ajax_cart_remove in controllers are followings.</p> <pre><code>function ajax_cart(){ $this-&gt;MOrders-&gt;updateCartAjax($this-&gt;input-&gt;post('ids')); } function ajax_cart_remove(){ $this-&gt;MOrders-&gt;removeLineItem($this-&gt;input-&gt;post('id')); } </code></pre> <p>And models for MOders are following.</p> <pre><code>function removeLineItem($id){ $id = id_clean($id); $totalprice = 0; $cart = $_SESSION['cart']; if (isset($cart[$id])){ unset($cart[$id]); foreach ($cart as $id =&gt; $product){ $totalprice += $product['price'] * $product['count']; } $_SESSION['totalprice'] = $this-&gt;format_currency($totalprice); $_SESSION['cart'] = $cart; echo "Product removed."; }else{ echo "Product not in cart!"; } } function updateCartAjax($idlist){ $cart = $_SESSION['cart']; $records = explode(',',$idlist); $updated = 0; $totalprice = $_SESSION['totalprice']; if (count($records)){ foreach ($records as $record){ if (strlen($record)){ $fields = explode(":",$record); $id = id_clean($fields[0]); $ct = $fields[1]; if ($ct &gt; 0 &amp;&amp; $ct != $cart[$id]['count']){ $cart[$id]['count'] = $ct; $updated++; }elseif ($ct == 0){ unset($cart[$id]); $updated++; } } } if ($updated){ $totalprice=0; foreach ($cart as $id =&gt; $product){ $totalprice += $product['price'] * $product['count']; } $_SESSION['totalprice'] = $this-&gt;format_currency($totalprice); $_SESSION['cart'] = $cart; switch ($updated){ case 0: $string = "No records"; break; case 1: $string = "$updated record"; break; default: $string = "$updated records"; break; } echo "$string updated"; }else{ echo "No changes detected"; } }else{ echo "Nothing to update"; } } </code></pre> <p>The following is the html output of form</p> <pre><code>&lt;form action="http://127.0.0.1/codeigniter_shopping_copy2/index.php/welcome/checkout" method="post"&gt;&lt;table border='1' cellspacing='0' cellpadding='5'&gt; &lt;tr valign='top'&gt; &lt;td&gt;&lt;input type="text" name="li_id[10]" value="1" id="li_id_10" class="process" size="5" /&gt;&lt;/td&gt; &lt;td id='li_name_10'&gt;Dress 1&lt;/td&gt; &lt;td id='li_price_10'&gt;33.95&lt;/td&gt; &lt;td id='li_total_10'&gt;33.95&lt;/td&gt; &lt;td&gt;&lt;input type='button' name='delete' value='delete' onclick='jsRemoveProduct(10)'&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr valign='top'&gt; &lt;td&gt;&lt;input type="text" name="li_id[6]" value="2" id="li_id_6" class="process" size="5" /&gt;&lt;/td&gt; &lt;td id='li_name_6'&gt;Shoes 1&lt;/td&gt; &lt;td id='li_price_6'&gt;23.95&lt;/td&gt; &lt;td id='li_total_6'&gt;47.90&lt;/td&gt; &lt;td&gt;&lt;input type='button' name='delete' value='delete' onclick='jsRemoveProduct(6)'&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr valign='top'&gt; &lt;td colspan='3'&gt;&amp;nbsp;&lt;/td&gt; &lt;td colspan='2'&gt;81.85 &lt;input type="hidden" name="name" value="total" /&gt; &lt;input type="hidden" name="id" value="total" /&gt; &lt;input type="hidden" name="value" value="81.85" /&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr valign='top'&gt; &lt;td colspan='3'&gt;&amp;nbsp;&lt;/td&gt; &lt;td colspan='2'&gt;&lt;input type='button' name='update' value='update' onclick='jsUpdateCart()'/&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr valign='top'&gt; &lt;td colspan='3'&gt;&amp;nbsp;&lt;/td&gt; &lt;td colspan='2'&gt;&lt;input type="submit" name="submit" value="checkout" /&gt;&lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;/form&gt; </code></pre>
    singulars
    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.
 

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