0

I write jsp code and run code by tomcat. tag button in tag form . Code JSP like that:

<form action="" method="get">
<div class="minicart"> 
    <a href="#" class="minicart_link"> <span class="item"><b>0</b> ITEM /</span> <span class="price"><b></b></span> </a>
    <div class="cart_drop">
        <span class="darw"></span>
        <div class="minicart">
            <a href="#" class="minicart_link"> <span class="item"><b>0</b> ITEM /</span> <span class="price"><b>$ 0 VND</b></span></a>
            <div class="cart_drop">
                <span class="darw"></span>
                <ul>
                    <li>Mời Bạn Hãy Mua Hàng Của Chúng Tôi</li>
                    <div class="cart_bottom">
                        <div class="subtotal_menu"><small>Tổng Cộng:</small><big>$ 0 VND</big></div>
                        <a href="../pageofwebsite/giohang.jsp">Checkout</a>
                    </div>
                </ul>
            </div>
        </div>
    </div>
</div>

<div class="add_to_buttons">
  <button id="addToCart" class="add_cart" name="3">Add to Cart</button>
</div>

When i click button have id="addToCart" , then source code in file mutation-summary.js is call return re-load this page. I don't want re-load this page when i click button. I don't no why? And file matation-summary.js is not in my source. Here code when i click button have id="addToCart".

$("#addToCart").click(function(event){
        $.ajax({
           type: "POST",
           url: "../gioHang",
           data: dataString,
           cache: false,
           success: function (html) {
               // xử lý lại chỗ này!!!
               //dataString= 'searchword='+ '';
               if(html.indexOf("alert") > 0){
                   var temp= $(".minicart").children();
                   $(".minicart").empty();
                   $(".minicart").append(html);
                   var length= temp.length;
                   var temp2= temp[length-2];
                   var temp3= temp[length-1];
                   //$(".minicart").append(temp[1]);
                   $(".minicart").append(temp2);
                   $(".minicart").append(temp3);
                }else{
                    $(".minicart").empty();
                    $(".minicart").append(html);
                }
                var dem=1;
                $(".minicart").click(function(){
                    if(dem %2 !=0){
                        $(".cart_drop").css({"display": "block"});
                        dem=2;
                    }else{
                        $(".cart_drop").css({"display": "none"});
                        dem=1;
                    }
                });
           }
        });

    });
Yên Đậu
  • 141
  • 1
  • 9

1 Answers1

0

The default type for a button is submit. See this: Can I make a <button> not submit a form?

Try updating your button to this code:

<button type="button" id="addToCart" class="add_cart" name="3">Add to Cart</button>
Community
  • 1
  • 1
Michael Freake
  • 1,197
  • 2
  • 14
  • 35