我在 post.php 中编写了一个脚本,用于删除购物车中的表格行。我正在使用 jquery post 将数据发送到 php 文件。这是我的 php 文件。我为输出创建了数组,并使用 json_encode 函数转换为 json。
//Sepetteki Ürünleri Siliyoruz
if(isset($_POST['deleteditems']) && isset($_SESSION['userid'])) {
$deleted_items = $_POST['deleteditems'];
//echo $_POST['deleteditems'];
$sql = "DELETE FROM basket WHERE productid IN ($deleted_items) AND userid = ".$_SESSION['userid'];
//echo $sql;
$query = mysql_query($sql);
$basket_array['queryresult'] = ($query) ? "<i class=\"icon-ok\"></i> Silindi" : "<i class=\"icon-remove\"></i> Hata: Silinemedi";
$basket_sql = "SELECT p.productid, p.wholesaleprice, p.minquantity, p.vat, b.quantity
FROM basket AS b, product AS p
WHERE b.productid = p.productid AND b.userid = ".$_SESSION['userid'];
$basket_query = mysql_query($basket_sql);
$num = mysql_num_rows($basket_query);
if ($num > 0) {
while ($row = mysql_fetch_array($basket_query)) {
$wholesaleprice = round($row['wholesaleprice']/(1+$row['vat']/100),2);
$total_quantity = $row['quantity']*$row['minquantity'];
$sumnovat[] = $total_quantity * $wholesaleprice;
$vats[] = array($row['vat'], round(($row['vat']/100)* $total_quantity * $wholesaleprice,2)); // KDV'yi hesaplıyoruz
}
foreach ($vats as $vat) {
$group_by_ratio_vat_sum[] = $vat[0];
}
$group_by_ratio_vat_sum = array_unique($group_by_ratio_vat_sum);
$group_by_ratio_vat_sum = array_fill_keys($group_by_ratio_vat_sum,0);
foreach ( $vats as $vat ) {
$number = str_replace( ",", ".", $vat[1] );
$group_by_ratio_vat_sum[ $vat[0] ] += (float)$number;
}
$total_vat = 0;
$basket_array['tfoot'] = '<tr class="basket_totals"><td colspan="5" class="basketresulttitle">'._('Ara Toplam').'</td><td colspan="3">'.number_format($sumnovat = array_sum($sumnovat),2).' TL</td></tr>';
foreach ($group_by_ratio_vat_sum as $vat_ratio => $vat_total) {
$basket_array['tfoot'] .= "<tr class=\"basket_totals\"><td colspan=\"5\" class=\"basketresulttitle\">"._('KDV')." (%$vat_ratio)</td><td colspan=\"3\">".number_format($vat_total,2)." TL</td></tr>";
$total_vat += $vat_total;
}
$basket_array['tfoot'] .= '<tr class="basket_totals"><td colspan="5" class="basketresulttitle">'._('Genel Toplam').'</td><td colspan="3">'.number_format($sumnovat + $total_vat,2).' TL</td></tr>';
json_encode($basket_array);
}
}
这是我的 jquery 代码。我想在我的 jquery 脚本中使用 json 对象。但我不能那样做。因为我是 json-jquery-php 关系的新手。你能帮助我吗 ?
$('#basket_delete_button').live('click',function(){
var loading = '<img src="<?php echo URL; ?>images/style/loading.gif" width="16" height="16">';
$('.loading').html(loading);
var deleteditems = $('tbody tr input:checkbox[name="delete_basket[]"]:checked')
.map(function() { return $(this).val() })
.get()
.join(",");
$.post('post.php',{deleteditems: deleteditems},function(data){
var obj = JSON.parse(data);
$('tfoot').html(obj.tfoot);
$("tbody tr :checked").each(function() {
$(this).parent().parent().remove()
});
var rowCount = $('.basket_products_row').length;
if (rowCount == 0){
$('#basket_area').html("<?php echo $basket_error; ?>");
$('#basket_count').text('0');
} else {
$('.loading').html(obj.queryresult);
}
});
});
我无法处理 jquery json php 关系。你能帮助我吗 ?我无法管理它。