我想知道如何在Laravel 4中调试ajax,因为当出现错误时,我只能得到一个500错误。
我正在使用jQuery进行ajax请求。
Log::info('Whatever you need to send to your log');
请检查您的日志以获取消息和所有错误消息:
php artisan tail
另一种方法是,为了更具体地了解错误(例如500内部服务器错误),将您的代码放入try/catch块中,并将错误/异常消息作为JSON对象发送。
$.post('http://localhost/post_request,
{
'_token': $('meta[name=csrf-token]').attr('content'),
'input_xxx': 'value'
})
.fail(function(data) {
data.error / data.debug
})
.success(function(data) {
});
--------------***---------------
(此为标记符号,无需翻译) try{
//post request action(s) handling here
}catch(Exception $e){
return response()->json([
'error' => 'Whoops, looks like something went wrong.',
'debug'=> $e->getMessage()
]);
}