使用php和会话的jquery购物车
你好 我现在通过创建一个基本的购物车来学习这个jquery,在jquery中添加到购物车按钮、删除项目和清除按钮都起作用 该函数用于保存会话中添加的项,还可以通过jquery删除和清除。现在我对jquery如何添加项有了一个想法。但不是移除单个项目或清除购物车上的所有项目 任何帮助、建议都将不胜感激 谢谢…:D 这是我到目前为止在购物车上完成的代码。这是在两个文件中,index.php和cart.php是“添加到购物车”按钮,除了“删除”和“清除”之外,其他按钮都已在工作。因为我还不能运行会话 这是:使用php和会话的jquery购物车,php,jquery,session,cart,shopping,Php,Jquery,Session,Cart,Shopping,你好 我现在通过创建一个基本的购物车来学习这个jquery,在jquery中添加到购物车按钮、删除项目和清除按钮都起作用 该函数用于保存会话中添加的项,还可以通过jquery删除和清除。现在我对jquery如何添加项有了一个想法。但不是移除单个项目或清除购物车上的所有项目 任何帮助、建议都将不胜感激 谢谢…:D 这是我到目前为止在购物车上完成的代码。这是在两个文件中,index.php和cart.php是“添加到购物车”按钮,除了“删除”和“清除”之外,其他按钮都已在工作。因为我还不能运行会话
<script type="text/javascript">
// for ajax
$(document).ready(function(){
$(".add").click(function(){
var id = $(this).attr("proid");
var item = $("#item"+id).val();
var brand = $("#brand"+id).val();
var price = $("#price"+id).val();
var quantity = $("#quantity"+id).val();
$.ajax({
type: "POST",
url: "cart.php",
data: "id="+ id + "& item="+ item + "& brand="+ brand +"& price="+ price +"& quantity="+ quantity,
success: function(data){
$("#jcart").html(data);
}
}); //ajax
return false;
}); //click function
//show empty table
$("#jcart").load("jcart.php");
//--> for options
$(".remove").click(function(){
var id = $(this).attr("proid");
$.ajax({
type: "POST",
url: "clear.php",
data: "id="+ id,
success: function(data){
$('#jcart').html(data)
}
});
});
$(".clear").click(function(){
$.ajax({
type: "POST",
url: "clear.php",
success: function(data){
$("#jcart").html(data)
}
});
});
});
</script>
//对于ajax
$(文档).ready(函数(){
$(“.add”)。单击(函数(){
var id=$(this.attr(“proid”);
var item=$(“#item”+id).val();
var brand=$(“#brand”+id).val();
var price=$(“#price”+id).val();
变量数量=$(“#数量”+id).val();
$.ajax({
类型:“POST”,
url:“cart.php”,
数据:“id=“+id+”&item=“+item+”&brand=“+brand+”&price=“+price+”&quantity=“+quantity,
成功:功能(数据){
$(“#jcart”).html(数据);
}
});//ajax
返回false;
});//单击函数
//显示空表
$(“#jcart”).load(“jcart.php”);
//-->选择
$(“.remove”)。单击(函数(){
var id=$(this.attr(“proid”);
$.ajax({
类型:“POST”,
url:“clear.php”,
数据:“id=”+id,
成功:功能(数据){
$('#jcart').html(数据)
}
});
});
$(“.clear”)。单击(函数(){
$.ajax({
类型:“POST”,
url:“clear.php”,
成功:功能(数据){
$(“#jcart”).html(数据)
}
});
});
});
我在讨论如何保存然后检索项目时遇到了困难。任何想法或帮助都将不胜感激
提前谢谢 有相当多的教程可以创建(听起来像)您想要的内容