Is this dynamic div getting refreshed before posting?
===

The following code works on a dev machine but is inconsistent when the get/post is over a network.
 
    $.getJSON('Products', function(data) {
        $.each(data, function(i, product) {
            var div1 = $('<div class="button">').attr({'name':product.name,'desc':product.desc}).appendTo($('#someOther'));
        });

        $(".button").click(function() {
            var prodDesc = $(this).attr('desc');
            var prodName = $(this).attr('name');
            $.ajax({
                type: "POST",
                url: "Cart",
                data: { action: "add", name: prodName, desc: prodDesc }
            })
        });
    });
    $.getJSON('Cart',function(data) {
        $.each(data, function(i,cart){
        ...
    });

Why does this happen ? My guess is that click doesn't get a chance to POST because the div gets refreshed ? If so, how can this be fixed given that the button is dynamic and the click has to be handled from within the function it's created ?