Yii Framework Forum: Ajax action returning error 500 along with data - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Ajax action returning error 500 along with data

#1 User is offline   Maxxer 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 106
  • Joined: 23-February 11
  • Location:Lecco (LC) - Italy

Posted 13 May 2017 - 10:42 AM

Hi. I'm using Kartik's DepDrop (as I've used in the past) and I created an action to return data for a dropdown, but I'm getting a weird error: the server returns error 500, but returns also the content!

For example in the controller I've created this action:
    public function actionCerca()
    {
        Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;        
        return ['output' => [], 'selected' => 0];
     }


if I call it from the browser I get Internal Server Error BUT also the JSON encoded array.
The controller is standard, I made no customization and no additional filter or behavior.

How can it be? Thanks
YetOpen S.r.l. - Your Open Source Partner
Lecco - Italy
http://www.yetopen.it
0

#2 User is offline   Roberto Braga 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 186
  • Joined: 18-February 13
  • Location:Roma, Italy

Posted 14 May 2017 - 01:39 AM

Error 500 is an internal server error.
The reason can be from server overload to access denied to some resources to a misconfiguration in an .htaccess file.
At first try to check if there is any hint in you webserver log.
Anyway since you say that you get the output, the error happen after the script execution, so no configuration error should be involved. Also the overload should be excluded for the same reason.
Try guessing it is a write permission problem on the runtime directory.
At the end of the execution yii write runtime information (log, debug etc etc) in that directory.
0

#3 User is offline   Maxxer 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 106
  • Joined: 23-February 11
  • Location:Lecco (LC) - Italy

Posted 15 May 2017 - 12:49 AM

indeed I've been stupid in not checking web server's error log! There's an exception on User model, which is rather strange as I've set no authentication in my project. Apparently the debug toolbar still requires an user. Commenting out the debug toolbar in config/web.php fixed. Maybe this is an issue which should be filed to the project?

thanks for the suggestion.

[Mon May 15 07:11:52.170375 2017] [:error] [pid 10203] [client ::1:60493] PHP Fatal error: Uncaught Error: Class 'app\\models\\User' not found in /project/vendor/yiisoft/yii2/web/User.php:657
Stack trace:
#0 /project/vendor/yiisoft/yii2/web/User.php(188): yii\\web\\User->renewAuthStatus()
#1 /project/vendor/yiisoft/yii2/base/Component.php(132): yii\\web\\User->getIdentity()
#2 /project/vendor/yiisoft/yii2-debug/panels/UserPanel.php(54): yii\\base\\Component->__get('identity')
#3 /project/vendor/yiisoft/yii2-debug/LogTarget.php(54): yii\\debug\\panels\\UserPanel->save()
#4 /project/vendor/yiisoft/yii2-debug/LogTarget.php(118): yii\\debug\\LogTarget->export()
#5 /project/vendor/yiisoft/yii2/log/Dispatcher.php(188): yii\\debug\\LogTarget->collect(Array, true)
#6 /project/vendor/yiisoft/yii2/log/Logger.php(177): yii\\log\\Dispatcher->dispatch(Array, true)
#7 [internal function]: yii\\log\\Logger->flush(true)
#8 {main in /project/vendor/yiisoft/yii2/web/User.php on line 65

YetOpen S.r.l. - Your Open Source Partner
Lecco - Italy
http://www.yetopen.it
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users