如何在Laravel 4中调试Ajax

3

我想知道如何在Laravel 4中调试ajax,因为当出现错误时,我只能得到一个500错误。

我正在使用jQuery进行ajax请求。


如果您想查看请求,可以使用浏览器扩展Firebug。但是您也可以检查应用程序的日志文件以了解500错误。 - user2629998
在Chrome Dev Tools中,不需要扩展或日志。请参见下面的Chrome中最简单的答案。 - Mike
3个回答

6

真是救命恩人:)) - Tadas V.

3
使用 Laravel Log 对 Laravel 进行调试:
Log::info('Whatever you need to send to your log');

请检查您的日志以获取消息和所有错误消息:

php artisan tail

0

另一种方法是,为了更具体地了解错误(例如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()
            ]);
    }

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接