如何设置正确的 json 标头?
htaccess 有没有办法确保我的 json 标头正确?
更新:有人发现这些 json 标头有什么问题吗?
Date Mon, 26 Jul 2010 08:31:11 GMT
Server Apache/2.2.15 (Unix) mod_ssl/2.2.15 OpenSSL/0.9.7a mod_fcgid/2.3.5 Phusion_Passenger/2.2.15 mod_auth_passthrough/2.1 mod_bwlimited/1.4 FrontPage/5.0.2.2635
X-Powered-By PHP/5.2.13
X-Pingback http://brettbarros.com/wordpress/xmlrpc.php
Content-Disposition attachment; filename="json_api.json"
Vary Accept-Encoding
Content-Encoding gzip
Content-Length 719
Keep-Alive timeout=5, max=98
Connection Keep-Alive
Content-Type application/json; charset=UTF-8
具体来说,它可以在 ie8、ffx、chrome 中使用 jquery 的 getJSON,但不能在 ie7 或 ie6 中使用...
Is there a way in htaccess to ensure the headers for my json are correct?
Update: Does anyone see anything wrong with these headers for json?
Date Mon, 26 Jul 2010 08:31:11 GMT
Server Apache/2.2.15 (Unix) mod_ssl/2.2.15 OpenSSL/0.9.7a mod_fcgid/2.3.5 Phusion_Passenger/2.2.15 mod_auth_passthrough/2.1 mod_bwlimited/1.4 FrontPage/5.0.2.2635
X-Powered-By PHP/5.2.13
X-Pingback http://brettbarros.com/wordpress/xmlrpc.php
Content-Disposition attachment; filename="json_api.json"
Vary Accept-Encoding
Content-Encoding gzip
Content-Length 719
Keep-Alive timeout=5, max=98
Connection Keep-Alive
Content-Type application/json; charset=UTF-8
Specifically, it's working with jquery's getJSON in ie8, ffx, chrome, but not ie7 or ie6...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
是一种使所有
*.json
文件以正确的 mime 类型发送的简单方法。当然,如果您在 PHP 脚本之类的东西中动态创建它们,那是行不通的。在这种情况下,您可以在脚本中添加信息:is a simple way to make all your
*.json
files being sent with the correct mime type. That, of course, doesn't work, if you create them dynamically in something like a, say, PHP script. In that case, you can add the info inside the script:您可以使用 Firebug 的 Net 选项卡检查从服务器端发送的标头。它显示请求和响应的所有标头。
You can inspect the headers sent along from the server side using Firebug's Net tab. It shows all the headers for both the request and the response.
确保内容类型为
application/json
。如果您不确定它们是什么,您可以使用 wget 等检查 http 标头。Make sure the Content-Type is
application/json
. You can inspect the http headers with wget and whatnot if you aren't sure what they are.