0

I have a strange problem. There is an Ajax request (POST), which sends data to the CodeIgniter 3 endpoint and everything is ok. The data is send and I can access it there, but in the PHP, when I try something like:

echo json_encode([
            'success' => false,
            'message' => 'Not found'
]);

- empty response

The only way to output this is to 'echo' something BEFORE that like this:

echo 1;
echo json_encode([
            'success' => false,
            'message' => 'Not found'
]);
  • 1{"success":false,"message":"Not found"}

It can be a char or a bool true (which is 1 in the browser response) and it must be before json_encode.

I have tried to set up headers to the response json or html, but with no effect. It is the same and with Postman.

Edit.

This works, too:

echo json_encode('test');

, but I need a collection.

Álvaro González
  • 142,137
  • 41
  • 261
  • 360
gdfgdfg
  • 3,181
  • 7
  • 37
  • 83

1 Answers1

0
     return json_encode([
        'success' => false,
        'message' => 'Not found'
        ]);