I have created a query it was working before but when i tried to get data in json format though it is not working i do not know why it is not showing data in return here is my code. when I checked the console the return data is not showing though not even it is processing I think so but I am unable to rectify the problem the bug. can any one please help me out.
$(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);
}
});
}));
});
his is my php code which I have created for processing the data
$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);