首页 > 解决方案 > 当我单击“添加到图表”并且通知是成功或失败时,我想使用 ajax laravel 发出通知

问题描述

当我单击“添加到购物车”并且通知是成功或失败时,我想使用 ajax laravel 发出通知。

这是我的脚本 ajax

<script>
    $('#formCart').on('click','.add_cart_btn',function(event) {
      $.ajax({
          url: '{{route("add-cart", "glove-botswana-abu-m-f0a9d79f-a575-4221-bead-60ed76afd972")}}',
          type: 'GET',
          dataType: "json",
          data: $('#formCart').serialize(),
          success: function(response){
              $('#overlay').remove();
              if(response.status == "success"){
                  // $.notifyBar({ cssClass: "success", html: "Order successfully added to cart", delay: 500, animationSpeed: "fast" });
                  notification('success', 'Order successfully added to cart');
                  $('.badge').html(response.carts);
                  $('.contentCart').html(response.content);
                  removeCart();
              }else{
                  // $.notifyBar({ cssClass: "error", html: "Order failed added to cart", delay: 500, animationSpeed: "fast" });
                  notification('success', 'Order failed added to cart');
                  removeCart();
              }
          }
      });
  });
</script>

这是我在刀片中的按钮

<button type="button" class=" btn btn-small btn-dark .add_cart_btn">Add to cart</button>

当我运行这个没有任何变化时,按钮没有通知。我应该怎么做才能在 laravel 中使用 ajax 进行通知

标签: javascriptphpjqueryajaxlaravel

解决方案


阿贾克斯:

$('.add_cart_btn').on('click',function(event) {
  $.ajax({

按钮:

<button type="button" class="btn btn-small btn-dark add_cart_btn">Add to cart</button>

推荐阅读