Note that there are some explanatory texts on larger screens.

plurals
  1. PONo post data in ajax call
    text
    copied!<p>im having problems with an ajax request. the function is to increment/decrement items in a shopping cart. When the increment event is fire the post array comes up empty when printed.</p> <p>Firebug shows the params being sent in the post request but in the controller nothing arrives.</p> <p>The solution implemented is a bit scruffy but this is the way it has to be. The jquery is a non anonymous method outside the document.ready signature which could well be a contributor to the issue.</p> <p>here's what I have...</p> <p>jQuery</p> <pre><code> function increment_item($ciid){ $("#processing").fadeIn("fast"); $.ajax({ url: "&lt;?=BASE_URL?&gt;landing/inc_cart_item", type: "post", dataType: "json", data: {id:$ciid,}, success: function(data){ $("#processing").fadeOut("fast"); if(data.error) { alert(data.error); } else { // parent.$('#line1').text(data.line1); //parent.$('#line2').text(data.line2); //parent.$('#address-dialog').dialog('close'); alert(data.line1); } } }); //return false; }; </code></pre> <p>The trigger in the view...</p> <pre><code>&lt;a href="#" onClick="increment_item(&lt;?=$item['cart_item_id']?&gt;)" class="qty-inc-button" &gt;More&lt;/a&gt; </code></pre> <p>The controller method...</p> <pre><code> function inc_cart_item(){ $return_val = $this-&gt;cart_model-&gt;increment_cart_item($this-&gt;session-&gt;userdata('cart_id'),$this-&gt;input-&gt;post('id')); } </code></pre> <p>EDITED TO ADD GENERATED SOURCE...</p> <p>The table data</p> <pre><code> &lt;/thead&gt; &lt;tbody id="item_2823"&gt; &lt;tr&gt; &lt;td&gt; &lt;img src="http://localhost/cdn/images/112/7/thumb_lemberger2010.jpg"&gt; &lt;p style="color: #666;"&gt;Bader&lt;/p&gt; &lt;p style="font-size: 16px;"&gt;Stettener Lindhälder Lemberger&lt;/p&gt; &lt;a href="#" onclick="remove_item(2823)" id="remove-item-button" class="remove-item-button"&gt;Remove this item&lt;/a&gt; &lt;/td&gt; &lt;td class="align-td-center"&gt; 8.20€ &lt;/td&gt; &lt;td class="align-td-center"&gt; &lt;a href="#" onclick="increment_item(2823)" id="qty-inc-button" class="qty-inc-button"&gt;More&lt;/a&gt; 1 &lt;a href="#" onclick="decrement_item(2823)" id="qty-dec-button" class="qty-dec-button"&gt;Less&lt;/a&gt; &lt;input id="item_id" class="item_id" value="2823" type="hidden"&gt; &lt;/td&gt; &lt;td class="align-td-center"&gt; &lt;span id="value-shipping-2823"&gt;8.20€&lt;/span&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/tbody&gt; &lt;tbody id="item_2824"&gt; &lt;tr&gt; &lt;td&gt; &lt;img src="http://localhost/***/cdn/images/112/5/thumb_kerfttropfle2010.jpg"&gt; &lt;p style="color: #666;"&gt;Bader&lt;/p&gt; &lt;p style="font-size: 16px;"&gt;Kerftströpfle&lt;/p&gt; &lt;a href="#" onclick="remove_item(2824)" id="remove-item-button" class="remove-item-button"&gt;Remove this item&lt;/a&gt; &lt;/td&gt; &lt;td class="align-td-center"&gt; 5.10€ &lt;/td&gt; &lt;td class="align-td-center"&gt; &lt;a href="#" onclick="increment_item(2824)" id="qty-inc-button" class="qty-inc-button"&gt;More&lt;/a&gt; 1 &lt;a href="#" onclick="decrement_item(2824)" id="qty-dec-button" class="qty-dec-button"&gt;Less&lt;/a&gt; &lt;input id="item_id" class="item_id" value="2824" type="hidden"&gt; &lt;/td&gt; &lt;td class="align-td-center"&gt; &lt;span id="value-shipping-2824"&gt;5.10€&lt;/span&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/tbody&gt; </code></pre> <p>Generated jquery</p> <pre><code>function increment_item($ciid){ $("#processing").fadeIn("fast"); $.ajax({ url: "http://localhost/***/***/landing/inc_cart_item", type: "POST", dataType: "json", data: {id:$ciid}, success: function(data){ $("#processing").fadeOut("fast"); if(data.error) { alert(data.error); } else { // parent.$('#line1').text(data.line1); //parent.$('#line2').text(data.line2); //parent.$('#address-dialog').dialog('close'); alert(data.line1); } } }); }; </code></pre> <p>Again the jQuery function im trying to use here is outside all the other generated jQuery in the $(document).ready(function() { code block, i dont know if this could be the cause.</p> <p>I've been wrestling with it a little while now, all help is appreciated.</p> <p>Thanks</p>
 

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