Ajax does not work when the shape is loaded



  • Hello, there's ajax basket.

    <form action="" id="form1" method="post">
    <input name="name" type="hidden" value="Название" />
    <input name="price" type="hidden" value="5000" />
    <input name="id" type="hidden" value="5" />
    <button class="cart">Купить</button>
    </form>
    

    and violin

    <script type="text/javascript">
        $(document).ready(function () {
            $(".cart").click(function() {
                var parent = $(this).parent();
                var id = parent.children()[0].value;
                var name = parent.children()[1].value;
                var price = parent.children()[2].value;
    
            $.ajax({
                type: "POST",
                url: "/ajax/add_to_cart/",
                data: {id: id,name: name, price:price},
                success: function(data){$(".cart").attr('disabled','disabled').html('Добавлено');}
            });
    
            return false;
        });
    });
    

    </script>

    It's working, but it doesn't work if I put the shape downloading the load.

    P.S. Jquery ajax only learn



  • $(document).ready(function () {
            $(".cart").live('click',function() {
                var parent = $(this).parent();
                var id = parent.children()[0].value;
                var name = parent.children()[1].value;
                var price = parent.children()[2].value;
    
                $.ajax({
                    type: "POST",
                    url: "/ajax/add_to_cart/",
                    data: {id: id,name: name, price:price},
                    success: function(data){$(".cart").attr('disabled','disabled').html('Добавлено');}
                });
    
                return false;
            });
        });
    



Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2