jquery - AutoRender = False doesn't work in CakePHP -


been trying figure out hours can't work!

i'm following this tutorial implement simple shopping cart feature using ajax , cakephp

in cartscontroller, have set: $this->autorender = false; since ajax call doesn't need load 'add' view. however, when click 'add cart' button, returns blank page correct quantity number. if go page , refresh it, can see item has been added cart.

how disable blank page (with qty) loading , have ajax update cart counter?

cakephp:

public function add() { $this->autorender = false;  if ($this->request->is('post')) {     $this->cart->addproduct($this->request->data['cart']['product_id']); }  echo $this->cart->getcount(); } 

fyi:

  • addproduct loops through array in session , increments variable (if found) or adds array (if not found)
  • getcount returns count of items in array.

ajax:

<script>     $(document).ready(function(){         $('#add-form').submit(function(e){             e.preventdefault();             var tis = $(this);             $.post(tis.attr('action'),tis.serialize(),function(data){                 $('#cart-counter').text(data);             });         });     }); </script> 

fyi, i'm making reference jquery in default.ctp:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script> 

please check jquery added before custom javascript code. if not, $ variable won't loaded , ajax call won't execute @ all.


Comments

Popular posts from this blog

java - Intellij Synchronizing output directories .. -

git - Initial Commit: "fatal: could not create leading directories of ..." -