|
|
|
ช่วยแนะนำทีครับ Shopping Cart jQuery ลบรายการไม่ออกกับ Checkout ไม่ขึ้น |
|
|
|
|
|
|
|
ลองเอา Code มาแปะด้วยครับ ว่าตรงไหนที่มีปัญหาครับ
|
|
|
|
|
Date :
2013-02-07 16:57:29 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Code (JavaScript)
Code (PHP)
var purchased=new Array();
var totalprice=0;
$(document).ready(function(){
$('.product').simpletip({
offset:[40,0],
content:'<img src="img/ajax_load.gif" alt="loading" style="margin:10px;" />',
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<purchased.length;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>=10) 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<purchased.length;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();
}
}
แล้วก็ตรงนี้ส่วนลบครับ
Code (PHP)
<?php
require("../config.inc.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 product WHERE img='img/products/".$img."'"));
echo '{status:1,id:'.$row['Pid'].',price:'.$row['Price'].',txt:\'\
\
<table width="100%" id="table_'.$row['Pid'].'">\
<tr>\
<td width="60%">'.$row['Pname'].'</td>\
<td width="10%">$'.$row['Price'].'</td>\
<td width="15%"><select name="'.$row['Pid'].'_cnt" id="'.$row['Pid'].'_cnt" onchange="change('.$row['Pid'].');">\
<option value="1">1</option>\
<option value="2">2</option>\
<option value="3">3</option>\
<option value="4">4</option>\
<option value="5">5</option>\
<option value="6">6</option>\
<option value="7">7</option>\
<option value="8">8</option>\
<option value="9">9</option></slect>\
\
</td>\
<td width="15%"><a href onclick="remove('.$row['Pid'].');return false;" class="remove">remove</a></td>\
</tr>\
</table>\'}';
?>
|
ประวัติการแก้ไข 2013-02-07 17:09:52
|
|
|
|
Date :
2013-02-07 17:06:48 |
By :
kanokpong |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 04
|