【www.gdgbn.com--网页配色】

以前我们的购物车都是点击打开网页,都是web 2.0形式的,本文章提供这款php教程 ajax拖动购物车源码,可以拖动商品放在购物车里面,这样更好的适合用户习惯了。
*/
//download by http://www.111cn.net

/* database config */

$db_host  = "localhost";
$db_user  = "root";
$db_pass  = "dcfan2006";
$db_database = "test";

$link = mysql教程_connect($db_host,$db_user,$db_pass) or die("unable to establish a db connection");
mysql_select_db($db_database,$link);
mysql_query("set names utf8");

?>




php ajax拖动购物车源码
<script type="text/网页特效" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/jquery-ui.min.js"></script>

<script>
var purchased=new array();
var totalprice=0;

$(document).ready(function(){
 
 $(".product").simpletip({
  
  offset:[40,0],
  content:"loading",
  onshow: function(){
   
   var param = this.getparent().find("img").attr("src");
   
   if($.browser.msie && $.browser.version=="6.0")
   {
    param = this.getparent().find("img").attr("style").match(/src="([^"]+)"/);
    param = param[1];
   }
   
   this.load("ajax/tips教程.php",{img:param});
  }

 });
 
 $(".product img").draggable({
 
 containment: "document",
 opacity: 0.6,
 revert: "invalid",
 helper: "clone",
 zindex: 100
 
 });

 $("div.content.drop-here").droppable({
 
   drop:
     function(e, ui)
     {
      var param = $(ui.draggable).attr("src");
      
      if($.browser.msie && $.browser.version=="6.0")
      {
       param = $(ui.draggable).attr("style").match(/src="([^"]+)"/);
       param = param[1];
      }

      addlist(param);
     }
 
 });

});


function addlist(param)
{
 $.ajax({
 type: "post",
 url: "ajax/addtocart.php",
 data: "img="+encodeuricomponent(param),
 datatype: "json",
 beforesend: function(x){$("#ajax-loader").css教程("visibility","visible");},
 success: function(msg){
  
  $("#ajax-loader").css("visibility","hidden");
  if(parseint(msg.status)!=1)
  {
   return false;
  }
  else
  {
   var check=false;
   var cnt = false;
   
   for(var i=0; i    {
    if(purchased[i].id==msg.id)
    {
     check=true;
     cnt=purchased[i].cnt;
     
     break;
    }
   }
   
   if(!cnt)
    $("#item-list").append(msg.txt);
    
   if(!check)
   {
    purchased.push({id:msg.id,cnt:1,price:msg.price});
   }
   else
   {
    if(cnt>=3) return false;
    
    purchased[i].cnt++;
    $("#"+msg.id+"_cnt").val(purchased[i].cnt);
   }
   
   totalprice+=msg.price;
   update_total();

  }
  
  $(".tooltip").hide();
 
 }
 });
}

function findpos(id)
{
 for(var i=0; i  {
  if(purchased[i].id==id)
   return i;
 }
 
 return false;
}

function remove(id)
{
 var i=findpos(id);

 totalprice-=purchased[i].price*purchased[i].cnt;
 purchased[i].cnt = 0;

 $("#table_"+id).remove();
 update_total();
}

function change(id)
{
 var i=findpos(id);
 
 totalprice+=(parseint($("#"+id+"_cnt").val())-purchased[i].cnt)*purchased[i].price;
 
 purchased[i].cnt=parseint($("#"+id+"_cnt").val());
 update_total();
}

function update_total()
{
 if(totalprice)
 {
  $("#total").html("total: $"+totalprice);
  $("a.button").css("display","block");
 }
 else
 {
  $("#total").html("");
  $("a.button").hide();
 }
}
</script>


 
   

shopping cart


   

the best products at the best prices


   


   
   
     
            products
       
       
       
   
      
             
               

    $result = mysql_query("select * from internet_shop");
    while($row=mysql_fetch_assoc($result))
    {
     echo "";
    }

    ?>
               
               
               
           

       
       
       
       

   

 

   
   
     
            shopping cart
       
       
       
   
      
             
              shopping cart
     loading..
               

    


               
               
               
               
    
               
               

    

               
               
                checkout
               
         

       
       
       
       

   
 


tips.php

 

if(!$_post["img"]) die("there is no such product!");

$img=mysql_real_escape_string(end(explode("/",$_post["img"])));

$row=mysql_fetch_assoc(mysql_query("select * from internet_shop where img="".$img."""));

if(!$row) die("there is no such product!");

echo "".$row["name"]."

".$row["description"]."

price: $".$row["price"]."
drag it to your shopping cart to purchase it";
?>

addtocard.php加入购物车

define("include_check",1);
require "../connect.php";

if(!$_post["img"]) die("there is no such product!");

$img=mysql_real_escape_string(end(explode("/",$_post["img"])));
$row=mysql_fetch_assoc(mysql_query("select * from internet_shop where img="".$img."""));

echo "{status:1,id:".$row["id"].",price:".$row["price"].",txt:"


 
    ".$row["name"]."
    $".$row["price"]."
   

本文来源:http://www.gdgbn.com/wangyezhizuo/27778/