title: echo php variable with jquery ajax
body: <p>I'm making my first website and I've encountered a problem with AJAX. I have tried and searched a lot of things but I'm missing something, please help me on this one. I have products' count and it works fine, but I need to refresh page everytime when I add new product to cart to see difference, so I need to use AJAX on my php variable. Please help me write AJAX code. I really appreciate it, thanks a lot and have a good day!</p>
  
  <p>PHP Code:</p>
  
  <pre><code>&lt;?php
   $cart = new cart(); 
   $products = $cart-&gt;getCart(); 
   $sum = 0; 
   foreach($products as $product){ 
       $sum += $product-&gt;count;
   } 
   echo $sum; 
  ?&gt;  
  </code></pre>