我正在使用名为IBKCart的购物车,但我正在调整它以确认订单。购物车结帐允许使用指向更新的javascript文件的链接更新数量并重新显示结帐。我在html中添加了一个提交按钮,以便确认订单。问题是,如果通过链接更新数量,则提交按钮不执行任何操作。如果刷新页面,则提交将起作用。那不太理想。如果数量未更新,则提交按钮有效。这是代码:
<?php
function DisplayCheckOut(){
$chkOutArr = array();
$plural = ($this->getCartItems() > 1)? 's': '' ;
$this->order_disc = array();
$Chk = '
<div id="Cart_Container_DetailView">
<div id="Car_top_bg"></div>
<div class="insideContQty"><strong>' . $this->getCartItems() . '</strong> item'. $plural .' in your cart '
. ' <a href="#" class="block" '
. ' onclick="if(confirm(\'Are you sure?\')){doCart(\'EmptyCart\', \'' . 0 . '\', 0, \'\', \'ChkOut\');} "
>Empty Cart </a>
<br />
</div>
<div id="">
<table width="100%" border="0" cellspacing="2" cellpadding="2">
<tr bgcolor="#6495ed">
<td width="30%" height="21"><div align="center"><strong>Item Description </strong></div></td>
<td width="5%"><div align="center"><strong>Qty</strong></div></td>
<td width="5%"><div align="center"><strong>Order Type</strong></div></td>
<td width="5%"><div align="center"><strong>Sale Type</strong></div></td>
<td width="10%"><div align="center"><strong>Price before disc.</strong></div></td>
<td width="10%"><div align="center"><strong>Discount</strong></div></td>
<td width="10%"><div align="center"><strong>Price after disc.</strong></div></td>
<td width="10%"><div align="center"><strong>Sub-total</strong></div></td>
<td width="5%"><div align="center"><strong>Qty in Stock</strong></div></td>
<td width="5%"><div align="center"><strong>Del</strong></div></td>
</tr>
';
//$this->count = array();
foreach($this->cart as $itemId=>$Qty){
$ProdDts = $this->getProdDts($itemId);
$DiscDts = $this->getDiscDts($this->dcart[$itemId]);
$TypeDts = $this->getTypeDts($this->tcart[$itemId]);
$this->totAmt += $ProdDts[$this->prodPrc] * $Qty ;
$this->totDiscount += $ProdDts[$this->prodPrc] * $Qty * $DiscDts[$this->disc_perc]/100 ;
$Chk .='
<tr class="Angle90" >
<td valign="top" >
<table width="100%" border="0" cellspacing="1" cellpadding="0">
<tr>
<td valign="top">' . $ProdDts[$this->prodNm] .'</td>
</tr>
</table>
</td>...
More html code
...
';
}
$Chk .='
<td valign="top"> <tr>
<td height="26" colspan="4" valign="top">
<div align="center">
<a href="#" class="block"
onclick="doCart(\'UpdCart\', \'ItemId[]\', \'ItemQty[]\', \'ItemDisc[]\', \'ItemType[]\', \'ChkOut\');">
Update Cart Items
</a>
</div>
</td>
</tr>
<tr>
<td>
<form method="post" action="">
</td>
</tr>
<tr>
<td width="200">
<input type="submit" value="Confirm Order" name="submit" id="submit" />
</td>
</tr>
</form>
</table>
</div>
</div>
';
echo $Chk;
}
调用的javascript是:
function doCart(tDo, itemId, qty, disc, type, pgfrm){
Q = pgfrm;
if (isNaN(qty) || (qty < 0)){
//alert('Please enter a valid number');
//return;
}
Obj = getXMLObj();
if (Obj !== null && Obj !== undefined){
var url = 'frmAction_IBKCart/myCart.php?tDo='+ tDo + '&itemId=' + itemId + '&Qty=' + qty + '&Disc=' + disc + '&Type=' + type + '&pgfrm=' + pgfrm + '&sId=' + Math.random();
//alert('tDo: ' + tDo + ' itemId: ' + itemId + ' Qty: ' + qty + ' Disc: ' + disc + ' pgfrm: ' + pgfrm);
if (tDo == 'UpdCart'){
var itemID = doc.getElementsByName(itemId); var theItems ='';
var Qty = doc.getElementsByName(qty); var theQtys = '';
var Disc = doc.getElementsByName(disc); var theDiscs = '';
var Type = doc.getElementsByName(type); var theTypes = '';
for(i=0; i<itemID.length; i++){
theItems = theItems + ',' + itemID[i].value;
theQtys = theQtys + ',' + Qty[i].value;
theDiscs = theDiscs + ',' + Disc[i].value;
theTypes = theTypes + ',' + Type[i].value;
}
url = 'frmAction_IBKCart/myCart.php?tDo=' + tDo + '&itemId=' + theItems + '&Qty=' + theQtys + '&Disc=' + theDiscs + '&Type=' + theTypes + '&pgfrm=' + pgfrm + '&sId=' + Math.random();
//alert('tDo GET: ' + tDo + ' itemId: ' + theItems + ' Qty: ' + theQtys + ' Disc: ' + theDiscs + ' pgfrm: ' + pgfrm);
}
//alert('tDo: ' + tDo + ' itemId: ' + itemId + ' Qty: ' + qty + ' Disc: ' + disc + ' pgfrm: ' + pgfrm);
Obj.onreadystatechange = doingCart;
Obj.open('GET', url, true);
Obj.send(null);
}
}
以下是javascript接收端的代码:
if (isset($_GET['pgfrm'])) {
if ($_GET['pgfrm'] == 'ChkOut'){
if ($Cart->getCartItems() > 0){
$Cart->DisplayCheckOut();
}
else{
$Cart->DisplayEmptyCart('ChkOut');
}
}
else{
if ($Cart->getCartItems() == 0){
$Cart->DisplayEmptyCart('Small') ;
}
else{
echo $Cart->ShowCartWtPrd();
}
}
}
if (isset($_POST['submit']))
{
$Cart->ConfirmOrder();
/*
$pdf->getHdrDtl();
$pdf->Header();
$pdf->Footer();
$pdf->generatePDF();
*
*/
$Cart->sendOrderEmails($dealer_email);
$group = $_SESSION['sessgroup'];
if ($group == 1){
echo '
<script>
alert("Your order has been confirmed!");
</script>
';
echo '
<script >
doCart(\'EmptyCart\',\'0\', \'0\', \' \', \'partCheckOut\');
</script>
';
header("Refresh: 1; ../admin_menu.php");
exit;
}
if ($group == 2){
echo '
<script>
alert("Your order has been confirmed!");
</script>
';
echo '
<script >
doCart(\'EmptyCart\',\'0\', \'0\', \' \', \'partCheckOut\');
</script>
';
header("Refresh: 1; ../user_menu.php");
exit;
}
if ($group == 3){
echo '
<script>
alert("Your order has been confirmed!");
</script>
';
echo '
<script >
doCart(\'EmptyCart\',\'0\', \'0\', \' \', \'partCheckOut\');
</script>
';
header("Refresh: 1; ../admin_menu.php");
exit;
}
}
我已经看了好几天了,甚至尝试用以下方法刷新屏幕:
header("Location: ./myCart.php");
没有成功。
任何帮助都感激不尽。
我希望添加这个图表可以更清楚地了解我的代码在做什么以及问题出在哪里。有一个“onclick”,如果我先做它最终应返回到同一个屏幕,然后允许提交按钮。执行“onclick”后,单击提交按钮实际上不起作用。但是,如果提交首先完成则可行。我没有用调试器NetBeans解决这个问题。