我正在研究前端是AngularJS& amp;后端是Laravel4。
我正在使用barryvdh的laravel-debugbar包作为调试器
我的问题是调试栏在第一次加载页面或我刷新页面时显示数据
但是当我称之为api throw angular resourse时,是不是没有捕获。
我尝试过在文档中发布的AJAX调用配置,但仍无效。
在配置文件中: -
/* |-------------------------------------------------------------------------- | Capture Ajax Requests |-------------------------------------------------------------------------- | | The Debugbar can capture Ajax requests and display them. If you don't want this (ie. because of errors), | you can use this option to disable sending the data through the headers. | */ 'capture_ajax' => true,
在我的控制器中: -
Debugbar::addMessage('Another message', 'mylabel'); Debugbar::warning('Watch out..'); Debugbar::sendDataInHeaders();
-ND
答案 0 :(得分:2)
在网上搜索了很长时间后,我找到了解决这个问题的方法
请将此代码添加到您的app.js
.factory('httpInterceptor', function($q) { var handle_phpdebugbar_response = function(response) { if (phpdebugbar && phpdebugbar.ajaxHandler) { var headers = response && response.headers && response.headers(); if (!headers) { return; } var headerName = phpdebugbar.ajaxHandler.headerName + '-id'; var debugBarID = headers[headerName]; if (debugBarID) { phpdebugbar.loadDataSet(debugBarID, ('ajax')); } } }; return { request: function(config) { return config || $q.when(config); }, response: function(response) { if (response || $q.when(response)) { handle_phpdebugbar_response(response); return response || $q.when(response); } }, responseError: function(response) { handle_phpdebugbar_response(rejection); return $q.reject(response); } }; })
.config(function($httpProvider) { $httpProvider.interceptors.push('httpInterceptor'); })
这个是角度模块ng-phpdebugbar
答案 1 :(得分:0)
(适用Laravel5)强>
不是回复您的回复,而是将其发送到视图:
return \View::make('debug', ['data' => $response]);
而不是
return response()->json($response);
(不要忘记创建回显数据的视图)