Welcome Guest, Not a member yet? Register   Sign In
JavaScript Fetch returns an error when in development mode.
#5

(This post was last modified: 07-15-2024, 04:12 PM by kenjis.)

PHP Code:
    public function index()
    {
        $data = ['id' => 1];
        return json_encode($data);
    

Code:
$ curl localhost:8080 -v
...
* Request completely sent off
< HTTP/1.1 200 OK
< Host: localhost:8080
< Date: Mon, 15 Jul 2024 22:29:11 GMT
< Connection: close
< X-Powered-By: PHP/8.1.29
< Cache-Control: no-store, max-age=0, no-cache
< Content-Type: text/html; charset=UTF-8
<
{"id":1}
<script  id="debugbar_loader" data-time="1721082551.730907" src="http://localhost:8080/index.php?debugbar"></script><script  id="debugbar_dynamic_script"></script>...

PHP Code:
    public function index()
    {
        $this->response->setHeader('content-type''application/json');
        $data = ['id' => 1];
        return json_encode($data);
    


Code:
$ curl localhost:8080 -v
...
* Request completely sent off
< HTTP/1.1 200 OK
< Host: localhost:8080
< Date: Mon, 15 Jul 2024 22:31:11 GMT
< Connection: close
< X-Powered-By: PHP/8.1.29
< Cache-Control: no-store, max-age=0, no-cache
< Content-Type: application/json
< Debugbar-Time: 1721082671.745205
< Debugbar-Link: http://localhost:8080/index.php?debugbar_time=1721082671.745205
<
* Closing connection
{"id":1}



The following code is better.

PHP Code:
    public function index()
    {
        $data = ['id' => 1];
        return $this->response->setJSON($data);
    

https://codeigniter.com/user_guide/outgo...the-output
Reply


Messages In This Thread
RE: JavaScript Fetch returns an error when in development mode. - by kenjis - 07-15-2024, 03:36 PM



Theme © iAndrew 2016 - Forum software by © MyBB