javascript - 当我单击“添加到图表”并且通知是成功或失败时,我想使用 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 进行通知
解决方案
阿贾克斯:
$('.add_cart_btn').on('click',function(event) {
$.ajax({
按钮:
<button type="button" class="btn btn-small btn-dark add_cart_btn">Add to cart</button>
推荐阅读
- xml - XSLT:How to sub string address field without split/cut the word in xslt
- vba - Getting table data on website via VBA is very slow
- wordpress - Could’nt install plugins in wordpress
- amazon-iam - IAM Policy Resource Pattern Error With Conditionals
- excel - Putting Formula that covers space in VBA
- apache-karaf - 卡拉夫想要可选的进口?
- python - 如何使用 Excel VBA 处理空格?
- python - 如何在 Mac 上授予 Pycharm 相机访问权限以与 OpenCV 一起使用?Python 代码在终端中有效,但在 Pycharm 中无效
- java - Spring Security 支持多个身份验证提供者 LDAP 身份验证和 JPA
- php - 如何让我的注册表单页面与 php 一起使用?