Button not starting ajax call
Hello, My button, when clicked is not start the ajax call, I cannot work out why. This is my button:
- <button class='btn btn-default pull-right cart-delete' onClick='event.stopPropagation();' id='$product_id'>X</button>
The reason I added onClick='event.stopPropagation();' is because my button is in a bootstrap dropdown toggle and I need to keep the dropdown "down" even after the click in the cart.
And this is my jquery code:
- dataType: 'json',
- <script>
- $(document).ready(function(){
- $(".cart-delete").click(function(){
- var id = $(this).parent().attr("id");
- alert(id);
- $.ajax({
- type: "POST",
- data: id,
- url: "resources/templates/frontend/delete-cart.php",
- success: function(data)
- {
- $.get('resources/templates/frontend/update-cart.php')
- }
- });
- event.preventDefault();
- });
- });
- </script>
- From what I have found online, adding this "event.preventDefault();" should prevent
- the button to reload the page but when I click it I can see a very short browser reload(fraction of a second).
Thank you in advance for your help.