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

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

报告相同问题?

悬赏问题

  • ¥35 平滑拟合曲线该如何生成
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 自己瞎改改,结果现在又运行不了了
  • ¥15 链式存储应该如何解决
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站