donglei7152 2018-08-24 18:42
浏览 103
已采纳

如何在php中检查控制台上的变量值?

I want to check variable value in console I have tried everything but I am not getting the value in console.

 // Here I want to check $cart_id value before if Statement
 echo "Cart Id Before If Statement:" . $cart_id;

The above line is not working because the page add_cart skip and I am not able to check the value like I usually do. So I need to check this value on cosole like

console.log($cart_id);

But when I check console the console is showing empty. But When I click on network then I open preserve log then my file add_cart.php is showing and I am able to see cookie as well as form data but I have no idea how to check $cart_id in console or in any way.

I also tried in my helper.php class

function debug_to_console( $data ) {
$output = $data;
if ( is_array( $output ) )
    $output = implode( ',', $output);

echo "<script>console.log( 'Debug Objects: " . $output . "' ); 
</script>";
} 

And call it before my if statement

debug_to_console($cart_id); 

But above also not working for me. I am not able to check the result of $cart_id before if statement. Nothing show on console.

if ($cart_id != '') {

}else{

$items_json = json_encode($item);
$cart_expire = date("Y-m-d H:i:s",strtotime("+30 days"));
$db->query("INSERT INTO cart (items,expire_date) VALUES ('{$items_json}','{$cart_expire}') ");
$cart_id = $db->insert_id;
setcookie(CART_COOKIE,$cart_id,CART_COOKIE_EXPIRE,'/',$domain,false);
}

Your valuable suggestion would be welcome.

  • 写回答

1条回答 默认 最新

  • douzheng9221 2018-08-24 19:53
    关注

    If its only to debug your application code, you can simply add a dump in your php code before if statement, like -

    var_dump($cart_id);die();
    
    if ($cart_id != '') {...}
    

    As, the call is ajax, you will have an http call generated in network tab. Opening that select Response. There you will be able to see the value of $cart_id. That can be found as shown in below image -

    enter image description here

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 有没有整苹果智能分拣线上图像数据
  • ¥20 有没有人会这个东西的
  • ¥15 cfx考虑调整“enforce system memory limit”参数的设置
  • ¥30 航迹分离,航迹增强,误差分析
  • ¥15 Chrome Manifest扩展引用Ajax-hook库拦截请求失败
  • ¥15 用Ros中的Topic通讯方式控制小乌龟的速度,走矩形;编写订阅器代码
  • ¥15 LLM accuracy检测
  • ¥15 pycharm添加远程解释器报错
  • ¥15 如何让子窗口鼠标滚动独立,不要传递消息给主窗口
  • ¥15 如何能达到用ping0.cc检测成这样?如图