用php和session在jquery中的购物车 [英] Shopping cart in jquery with php and session

查看:90
本文介绍了用php和session在jquery中的购物车的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

美好的一天!

我现在正在通过创建一个基本的购物车来学习这种jQuery,就像在购物车中添加按钮,删除商品和清除按钮一样.

I'm now learning this jquery by creating a basic shopping cart were as add to cart buttons, remove items and clear buttons works in jquery.

该功能是将添加的项目保存在会话中,并且可以通过jquery删除和清除.我现在对jquery如何在添加项目上有一个想法.但不能移除单个物品或清除购物车中的所有物品.

The function is to save the added items on session and can remove and clear also by jquery. I have an idea now on how the jquery works on adding the items. But not on removing a single item or to clear all of them on the cart.

任何帮助,建议都将不胜感激.

Any help, suggestion are much appreciated.

谢谢...:D

这是我到目前为止在购物车上完成的代码.这是两个文件,除了删除和清除之外,index.php和cart.php是添加到购物车按钮已经起作用的按钮.因为我还不能运行会话.

Here is the code I have done so far on shopping cart. This is in two files the index.php and cart.php were the add to cart button already working except for remove and clear. Because I was not able to run the session yet.

这里是:

<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>

我在关于如何保存项目然后检索项目的会议上遇到了困难.任何想法或帮助将不胜感激...

I'm making difficult with the session on how the items being save then retrieve. Any ideas or help will much appreciated...

提前谢谢!

推荐答案

这里有很多教程可以创建(听起来像)您想要的东西.

There are a fair few tutorials out there which create (what sounds like) what you are looking for.

  • Tutorialzine : An AJAX Based Shopping Cart with PHP, CSS & jQuery
  • WebResourcesDepot : Creating A Slick Ajaxed Add-To-Basket With jQuery And PHP
  • WebResourcesDepot : Ajaxed Sliding Shopping Cart with jQuery

已阅读其中的内容以及会话PHP手册,然后看看您能想到什么.如果您先开始然后陷入困境,请回来,再问一些其他问题(包括示例和代码示例),我们将竭尽所能.

Have a read of them, along with the PHP Manual for Sessions, and see what you can come up with. If you make a start, and then get stuck, come back, ask some more questions (with examples and code samples) and we will do what we can to help.

这篇关于用php和session在jquery中的购物车的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆