我觉得写这段代码没有任何html和post url是不可能的。你必须给我们这个页面的链接。但让我试试。我认为你可以手动发送请求从jquery文件到购物车。或者为了更安全,您可以将帖子数量和用户发送到另一个php文件。在该PHP文件中,您可以计算奖品并将其发布到购物车。我与shopify不相似,但我试过运气。
$('#buy').click(function(){
quan=$('#quantity').val();
if(quantity >= 1 && quantity <=25){
//capture the user id
$.post("cart.php", { price: "5", quantity: quan, userId : user });
}else if(quantity >= 26 && quantity <=50){
//capture the user id
$.post("cart.php", { price: "4", quantity: quan, userId : user });
}
});
但不要忘记客户端脚本是危险的。尝试使用服务器端脚本从数量计算价格。下面的例子。
//Javascript
$('#buy').click(function(){
quan=$('#quantity').val();
//capture the user id
$.post("cart.php", { quantity: quan, userId = user });
});
这里是php文件捕获变量从请求和工作。
//PHP
<?php
$user= $_POST['userId'];
$quantity = $_POST['quantity'];
if(quantity >= 1 && quantity <=25){
//Change cart. Mysql or post manually to cart php and send the price 5
}else if(quantity >= 26 && quantity <=50){
//Change cart. Mysql or post manually to cart php and send the price 4
}
?>
我想要做类似的事情,你可以请建议你是如何解决你的问题? – user427969 2015-03-12 23:09:41