【问题标题】:Laravel flash popup notificationsLaravel flash 弹出通知
【发布时间】:2021-04-04 05:02:30
【问题描述】:

我在 jQuery + Bootstrap bootstrap-growl 上找到了一个很酷的弹出通知库。

我想专门使用它来将产品添加到购物车。

我尝试在按钮单击上放置一个处理程序,但通知如下所示:

Product <strong>{{ Session::get('add-product') }}</strong> added to cart

不处理大括号。

我尝试通过 session::flash 来实现,将接收到的值投射到 type = "hidden" 的输入上,但 flash 只在重启后触发,这不是我需要的。如何首先在输入中使用 ajax 加载值,然后在通知中加载?谁能给个思路?

如何尽可能正确地实现这一点?或者有哪些库允许从 session::flash 发出 toast 通知?

具有添加到购物车功能的CartController:

  public function addCart(Request $request, $id){
    $product = Product::find($id);
    $oldCart = Session::has('cart') ? Session::get('cart') : NULL;
    $cart = new Cart($oldCart);
    $cart->add($product, $product->id);

    $request = Session::put('cart', $cart);

    //Session::flash('add-product', $product->name);

    return response()->json([
         'total_quantity' => Session::has('cart') ? Session::get('cart')->totalQty : '0' 
     ]);
  }

如果可能,通过闪光灯查看:

    <div class="col-lg-12">
    @if(Session::has('add-product'))
        <p class="alert alert-success text-center mt-2  mb-1 addpopup">
           Product<strong>{{ Session::get('add-product') }}</strong> added to cart
        </p>
        <input type="hidden" class="addpopup">Product<strong>{{ Session::get('add-product') }}</strong> added to cart</input>
    @endif
    </div>

用于将产品添加到购物车的 Ajax,以及该库中触发通知的函数:

$(document).ready(function() {
$('.product-icon-container').find('.ajaxcartadd').click(function (event){
event.preventDefault();
$.ajax({
url: $(this).attr('href'),
dataType: 'JSON',
success: function(response) {
$('.prodcount').html(response.total_quantity);
}
});
$.bootstrapGrowl('Product<strong>{{ Session::get("add-product") }}</strong> added to cart', {
  ele: 'body', // which element to append to
  type: 'info', // (null, 'info', 'danger', 'success')
  offset: {from: 'top', amount: 20}, // 'top', or 'bottom'
  align: 'center', // ('left', 'right', or 'center')
  width: 'auto', // (integer, or 'auto')
  delay: 4000, // Time while the message will be displayed. It's not equivalent to the *demo* timeOut!
  allow_dismiss: true, // If true then will display a cross to close the popup.
  stackup_spacing: 10 // spacing between consecutively stacked growls.
});
return false;
});
});

【问题讨论】:

    标签: jquery ajax laravel popup


    【解决方案1】:

    我的情况下这个问题的解决方案你可以找到here

    【讨论】:

      猜你喜欢
      • 2023-01-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-11-04
      • 1970-01-01
      • 1970-01-01
      • 2013-06-10
      • 2011-10-02
      相关资源
      最近更新 更多