The problem with Pjax?

Hello, here's the situation: I click on button need to send two post request and update the contents of a specific block. Without Pjax requests are sent when you click many times, but if with him, then Pjax is update with every click, and the queries are only after the first click and all, only after refreshing the page srabatyvaet. I already all head broke, I do not understand what the problem is, please help, I attach the code
<?php Pjax::begin(); ?>
 <?php if($productsInCart):?>

 <table id="cart_products" cellspacing="0">
<tbody><tr>
<th>Delete</th>
<th>Name</th>
<th>Price</th>
<th>Quantity</th>
<th>Total</th>
</tr>

 <?php foreach($prods as $product):?>
the <tr>
 <td><a href="/cart/delete/<?php// echo $product['id'];?>" class="del">
 <img src="/img/del_prod_pic.png">
</a></td>
 <td><?= $product--->name;?></td>
 <td><?= $product['prices'][0]--->price;?></td>
<td>
 <?= $productsInCart[$product['id']];?> PCs
 <a href class="to_cart" data-id="<?= $product->id;?>">
 <img src="/img/plus.png">
</a>
 <a href="#" class="cart_del" data-id="<?= $product->id;?>">
 <img src="/img/minus.png">
</a>
</td>
 <td><?= Order::getProdTotalPrice($product--->id);?></td>
</tr>
 <?php endforeach;?>
 <tr id="total_sum">
<td></td>
<td></td>
<td></td>
 <td>total in cart: </td>
 <td><?= $totalPrice;?></td>
</tr>
</tbody></table>

 <a href="/cart/checkout" class="checkout">
 Checkout
</a>

 <?php else:?>
 <h2 id="empty_cart">empty Your cart</h2>
 <a href="/" id="empty_cart_to_main">Continue shopping</a>
 <?php endif;?>
 <?= Html::a("Update", ['/cart'], ['class' =--> 'refresh btn btn-lg btn-primary']);?>
 <?php Pjax::end(); ?>


JS
$(document).ready(function(){
$('.to_cart').click(function(){
 var id = $(this).attr("data-id");
 $.post("/toCart/"+id, {}, function(data){
 $('.span cart_count').html(data);
});
 $.post("/updateCount/"+id, {}, function(data){
 $('.to_cart span#prod_'+id).html(data);
});
$('.refresh').click();
 return false;
});
});
July 9th 19 at 12:56
1 answer
July 9th 19 at 12:58
Solution
$('body').on('click', '.to_cart' , function(){
...
});
Thank you!!!! - hillard.Little commented on July 9th 19 at 13:01

Find more questions by tags PHPYii