D
D
Dmitry2017-03-21 16:37:59
Yii
Dmitry, 2017-03-21 16:37:59

Why does Yii2 POST AJAX return 500 code but the response contains the correct data set?

It all started just recently, from scratch, as they say.
An AJAX POST request is sent from the browser, the request is processed correctly on the server side, but when data is returned from the action, the browser receives a 500 status despite the fact that the data also comes:
- i.imgur.com/fM1rv2o.png
- i.imgur.com/fp0dANe .png
The action returns data in JSON format:

<?php
//...
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
$data = [...];
return $data;
// ...
?>

If you return something from the action via echo - the same thing.
If you dump (dd or dump(), for example) - then 200 status.
What could be the reason?
Thank you.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry, 2017-03-31
@another_dream

There was nothing in the logs, the problem was empirically identified: E_WARNING, which, for some reason, was not displayed anywhere until it was manually intercepted by hanging an error handler

Solution (UPD)
set_error_handler(
            function ($errno, $errstr) use($data) {
                var_dump($errstr);
            },
            E_ALL
        );

session_write_close(): open(/var/www/mysite/data/mod-tmp/sess_s8jm3ltvjbwermqsdr035rk6fp6, O_RDWR) failed: No such file or directory (2)"
string(162) "session_write_close(): Failed to write session data (files). Please verify that the current setting of session.save_path is correct (/var/www/mysite/data/mod-tmp)

It turned out that this directory did not exist at all, the solution is to create a directory and specify write permissions.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question