我正在尝试将数据发送到PHP文件。我已经成功序列化了数据,并在控制台上将其打印出来,以确认数据已被序列化。但是,当我使用PHP并尝试echo $_Post
时,它显示了一个空数组。为什么会这样?
var cartData = {
sessionID: $('.session').attr('name'),
};
var cartDat = $.param(cartData);
console.log(cartDat);
$.post('onloadcartquery.php',cartDat, function(data) {
// var output= JSON.parse(data);
$('span.header-icons-noti').text(data);
});
require_once 'data/functions.php';
$noofitems = 0;
print_r($_POST);
function numberofcartitems()
{
$query = "SELECT id FROM carts WHERE sessiondata ='$_POST[sessionID]'";
$connection = db_connect();
$rs = mysqli_query($connection, $query);
if (mysqli_errno($connection))
{
$error = db_error();
throw new Exception($error);
}
while ($row = mysqli_fetch_assoc($rs))
{
$noofitems++;
}
}
numberofcartitems();
echo json_encode($noofitems);