title: How to click a link that will execute but not redirect.
body: <p>I have a few products in a mySQL database whose links are being retrieved in my script with $producturl. These url's actually add the product to the cart (<a href="http://www.example.com/cart/?add-to-cart=1127" rel="nofollow">http://www.example.com/cart/?add-to-cart=1127</a>). I am trying to create a script that will allow the user to add products to the cart but NOT redirect them, just execute the link so the user stays on the same page. </p>
  
  <p>I am using preventDefault and stopPropgation but it is not working. The alert shows up but the link itself is not executing when I view my cart later the product is not there. Any help?</p>
  
  <pre><code>&lt;?php $producturl = ProductURL::find(array('Product'=&gt;$tube1-&gt;Tube1));
  if($producturl[0]-&gt;URL!=NULL){  
  echo '&lt;span id="shop"&gt;Add Cart NoRedirect&lt;/span&gt;';
  }
  ?&gt;
  
  &lt;script type="text/javascript"&gt;
  $(document).on('click', '#shop', function (event) {
   $.post( '&lt;?php echo $producturl[0]-&gt;URL; ?&gt;' );
  event.preventDefault();
  event.stopPropagation();
  alert('Product has been added to cart');
  });
  &lt;/script&gt;
  </code></pre>