我已經創建了一個查詢它工作之前,但是當我試圖以json格式獲取數據,雖然它不工作,我不知道爲什麼它不顯示數據作爲回報這裏是我的碼。當我檢查控制檯返回數據不顯示,但即使它不是處理我認爲,但我無法糾正問題的錯誤。任何人都可以幫助我。無法顯示通過ajax調用返回數據
$(document).ready(function(e) {
$("#addcart").on('submit', (function(e) {
var oldval = $('#crtcount').text();
var form = this;
var formData = new FormData(this);
$.ajax({
url : "includes/get_data.php",
type : "POST",
data : formData,
contentType : false,
cache : false,
processData : false,
dataType : "JSON",
success : function(data) {
var data = $.parseJSON(data);
$('#crtcount').html(parseInt(oldval)+1);
$('#crtcount1').html(parseInt(oldval)+1);
$('#cart_dt').html(data.cart);
console.log(data.message);
}
});
}));
});
他是我所處理的數據
$qty = $_POST['qty'];
$pid = $_POST['pid'];
echo $cart->add_to_cart($pid);
$data['message'] = "<div class='message'>Your product is added to cart</div>";
$data['cart'] = '';
foreach($_SESSION['cart']['pid'] as $content) {
$prod_id = $content['prod_id'];
$products = bgMysqlSelect("SELECT * FROM bg_products WHERE pid = '$prod_id'");
$data['cart'] .= '<div class="items-sm"><div class="img-sm"><img src="../includes/uploads'.$products['pimage'].'" /></div>';
$data['cart'] .= '<div class="cart-inf-sm"><h4>'.$products['ptitle'].'</h4>';
$data['cart'] .= '<p><span>price :</span>$'.$products['pmsrp'].'</p>';
$data['cart'] .= '<p><span>Qty :</span>'.$content['qty'].'</p>';
$data['cart'] .= '<a href=""><i class="fa fa-times"></i></a></div></div>';
}
echo json_encode($data);
你可以檢查F12網絡t ab瞭解你的php工作是否 – hasan
@hasan我檢查了網絡ab,我只看到這個我不知道如何檢查網絡選項卡上的bug –
按f12然後點擊網絡選項卡,然後點擊XHR過濾器,你會看到XHR請求 – hasan