切换到 Lighttpd 后,Ajax 在 Chrome 中停止工作

发布于 2024-09-30 14:34:59 字数 372 浏览 0 评论 0原文

我在 Chrome 中渲染 text/json 时遇到问题。我使用 YUI 库发送 ajax 请求并处理响应。

当我从使用 mod_php 的 Apache 切换到使用 php-fpm 作为 fastcgi 的 Lighttpd 后,问题就出现了。 Ajax 从服务器请求某些内容,服务器返回 text/json 类型的内容(在标头中声明内容 text/json)

可在除 Chrome 之外的所有浏览器中工作和呈现。这就是它的奇怪之处在于它可以在 Firefox、Safari、IE 中运行,但不能在 Chrome 中运行。

我不知道这里发生了什么事。我什至禁用输出压缩,因为我认为它导致了问题,但问题仍然没有消失。

我希望有人已经解决了这个问题并找到了解决方法。

I am having problem with rendering text/json in Chrome. I use YUI library to send ajax request and process response.

The problem appeared right after I switched from Apache with mod_php to Lighttpd with php-fpm as fastcgi. Ajax requests something from the server, server returns content of type text/json (declared content text/json in header)

Works and renders in all browsers Except for Chrome. That's what's so strange about it is that it works in Firefox, Safari, IE but not in Chrome.

I have no idea what's going on here. I even disable output compression because I though it was causing the problem, but the problem still did not go away.

I hope someone has alreade been through this problem and figured out how to fix it.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

离旧人 2024-10-07 14:34:59

这真是令人难以置信,但我将其归结为:
在服务器端,我使用 php 在发送输出之前设置标头,如下所示:
header("内容类型:text/json; charset=UTF-8");

它在所有浏览器中都工作得很好,除了 Chrome,它需要 Content-Type
注意大写的“T”
所以我把它改成这样后:
header("内容类型:text/json; charset=UTF-8");

Chrome 中也一切正常。
为什么它与 Apache/mod_php 一起工作而停止与 Lighttpd/fastcgi 一起工作?我猜
Apache 在实际发送之前以某种方式修复了所有标头,而 Lighttpd 并不真正关心。

我很惊讶我竟然能够追踪到这一点。

我希望我能因解决自己的问题而获得徽章,并希望它能帮助其他可能遇到同样问题的人。

This is pretty unbeleivable but I traced it down to this:
On the server side, using php I was setting the header just before sending the output, like this:
header("Content-type: text/json; charset=UTF-8");

It was working just fine for all browsers, except for Chrome, which expected the Content-Type
notice the upper case "T"
So after I changed it to this:
header("Content-Type: text/json; charset=UTF-8");

everything works in Chrome too.
Why was it working with Apache/mod_php and stopped working with Lighttpd/fastcgi? I guess
Apache was somehow fixing all the headers just before there were actually sent out and Lighttpd does not really care.

I am surprised I was even able to track this down.

I hope I earn a badge for solving my own question and hopefully it will help someone else who may be having the same problem.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文