为什么在Shopify购物车/添加API中使用警报只在firefox浏览器的购物车中添加产品?
问题描述:
I want to add a product in cart page of my Shopify website.I am using Shopify cart/add.js API for adding a product in cart.It's working in Google Chrome browse.But for Firefox it's not working.How can i do it in Mozilla Firefox using same API and withot using alert box?
I am performing event on click of Add to cart button
<button class="btn" id="add_raffle">
<span id="AddToCartText-product-template">Add to cart</span>
</button>
Form to post
<form action="/cart/add" id="raffle_prod">
<input type = "hidden" name="id" value = "13597453582389" id="raffle_variant">
<input type = "hidden" name="quantity" value = "1" >
<input type="submit" style="display:none" id="raffle_submit">
Jquery Code
$('#add_raffle').click(function(event){
var FIREFOX = /Firefox/i.test(navigator.userAgent);
if (FIREFOX) {
$('#raffle_submit').trigger("click");
alert('Raffle tickets added. Thanks!');
} else {
var dataString = $('#raffle_variant').serialize();
jQuery.post('/cart/add.js', dataString);
alert('Raffle tickets added. Thanks!');
}
});
This code is working for Google chrome.
But for Firefox following code is not working.I need to post a form and use alert after request then product is adding in cart.
I want to avoid alert and want to use same api code as i do for google chrome.
答
Check that if
statement in your jQuery code.
Fixed:
$('#add_raffle').click(function(event){
var dataString = $('#raffle_variant').serialize()
jQuery.post('/cart/add.js', dataString)});