-3

It works fine it returns me an json object after all if I write like this.

public function getElementsAction()
{
    $currency = App::$app->getProperty('currency');
    if(!empty($_POST))
    {
        $sql = 'SELECT name, price, file, time FROM listings WHERE id_item IN (' . implode(',', $_POST) . ')';
        $items = \R::getAll($sql);
        echo(json_encode($items));
    }
}

But what I want is get a string of var_dump and print out in console.log for further debuggin, what do I do then? I tried both ways and it gives me error in console.log :((

public function getElementsAction()
{
    $currency = App::$app->getProperty('currency');
    if(!empty($_POST))
    {
        $sql = 'SELECT name, price, file, time FROM listings WHERE id_item IN (' . implode(',', $_POST) . ')';
        $items = \R::getAll($sql);
        //echo(json_encode(var_dump($items))); // error
        //echo(json_encode(strval(var_dump($items)))); // error
        //echo(json_encode("Hi"); // No error
    }
}

or is it something I can see in Network somewhere? thank you!

1 Answers1

-2

If you want to console.log() in PHP you can do this:

function console($value) {
    $log = '<script>console.log(' . json_encode($value, JSON_HEX_TAG) . 
    ');' . '</script>';
    echo $log;
}

EDIT: Try it here

Moïze
  • 707
  • 8
  • 16