Welcome Guest, Not a member yet? Register   Sign In
JSON formatting in the browser (missing headers)?
#4

PHP Code:
return $this->setResponseFormat('json')->respond(['error' => false]); 
// equal
return $this->response->setJSON(['error' => false]);  

PHP Code:
// setResponseFormat($format) 
$this->format strtolower($format);

// respond($data) 
// $output contains json if $data not a string
if ($this->format === 'json')
{
    return $this->response->setJSON($output)->setStatusCode($status$message);


example code with browser output (pic, CI4.1 php 7.3) https://yadi.sk/i/VBFIGIaF-TLF2g

You can actually use setJSON() if you're comfortable.
I'm just showing that the example from the documentation works.

And by the way, when you passed the JSON string in the first example, the header was setted to text/html
link to code
Reply


Messages In This Thread
RE: JSON formatting in the browser (missing headers)? - by iRedds - 02-01-2021, 10:24 AM



Theme © iAndrew 2016 - Forum software by © MyBB