PHP returns 空白字符在 AJAX 请求之后的任何内容之前

PHP returns whitespace character before anything after AJAX request

我正在使用 XMLHttpRequest 从我的服务器获取一些数据。我使用第一个字母作为错误或成功的标志。这工作正常,但在没有更改服务器上的任何内容或 php 配置的情况下,请求开始 return 白色 space 第一个字符。我通过修剪它来处理它,但我想知道这是怎么发生的。如果有人可以提供帮助,我将不胜感激。我也可以给一些钱进行更深入的调查。在从 javascript 调用的我的 PHP 文件中。我将 const 值用于 true 或 false 标志,即 0 和 1。出了点问题,在此 const 变量之前,白色 space 正在 echoed.Is 它 php 回显它或 javascript 改变了行为并在 XMLHttpRequest 响应中添加了 whitespace?

追踪空白的来源或调用 phps ob_clean

来自manual

This function discards the contents of the output buffer.

This function does not destroy the output buffer like ob_end_clean() does.

The output buffer must be started by ob_start() with PHP_OUTPUT_HANDLER_CLEANABLE flag. Otherwise ob_clean() will not work.

我在使用 laravel 之前遇到过这个问题,这只是缓存 我用 php artisan cache:clear 清除了缓存,它起作用了,所以也许对你来说是一样的