简体   繁体   English

如何在Symfony2中为Ajax调用禁用调试(工具栏)?

[英]How do you disable Debug (Toolbar) for Ajax calls in Symfony2?

Does anyone know how to disable the debug toolbar for Ajax calls? 有谁知道如何禁用Ajax调用的调试工具栏?

I have tried this: 我已经试过了:

$this->container->get('profiler')->disable();

but didn't work. 但是没有用

I have a controller that returns a string (json encoded data). 我有一个返回字符串(JSON编码数据)的控制器。 And in the development environment I get 在开发环境中

<div class="debug"></div>

at the end of string which breaks my code. 在字符串的结尾,这破坏了我的代码。

Any help is appreciated. 任何帮助表示赞赏。

If you return a json string anyway just use JsonResponse in your controller. 如果仍然返回json字符串,则只需在控制器中使用JsonResponse

use Symfony\Component\HttpFoundation\JsonResponse;

$response = new JsonResponse();
$response->setData(array(
    'data' => 123
));

This should do the trick. 这应该可以解决问题。

found a leftover function from a legacy debug alternative that we have written to symfony's own debug toolbar in one of our listeners. 从一个旧式调试替代方法中找到了一个剩余函数,该函数已在侦听器之一中写入symfony自己的调试工具栏。 so there was no symfony issue but a developer error. 因此没有symfony问题,但有开发人员错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM