gzip编码与JSON兼容吗? [英] Is gzip encoding compatible with JSON?

查看:143
本文介绍了gzip编码与JSON兼容吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图缩小AJAX调用中的一些奇怪的事情。我的PHP脚本一开始就这样:

  ob_start(ob_gzhandler); 

适用于HTML。但是,在应用程序/ json数据中有什么问题吗?任何人都知道的任何浏览器问题?

解决方案

我不这么认为...我使用静态文件存储之前使用过gzip压缩的JSON,并且它与AJAX工作正常。



编辑:我检查了我的PHP脚本,我唯一做的是包括这些标题:

 内容编码:gzip 
内容类型:text / plain

如果我记得正确,每当我尝试将Content-Type更改为表示JSON的内容时,客户端就有问题。 p>

I'm trying to narrow down some weirdness going on with my AJAX calls. My PHP scripts have this at the start:

ob_start("ob_gzhandler");

Works great with HTML. But are there any problems with doing it with application/json data? Any browser issues anyone is aware of?

解决方案

I don't think so... I've used static files stored as gzipped JSON before, and it worked fine with AJAX.

edit: I checked my php script and the only thing special I did was to include these headers:

Content-Encoding: gzip
Content-Type: text/plain

If I remember right, whenever I tried to change the Content-Type to something that would indicate JSON, the client had trouble.

这篇关于gzip编码与JSON兼容吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆