我覺得寫這段代碼沒有任何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