【问题标题】:How do I set the correct json headers?如何设置正确的 json 标头?
【发布时间】:2014-07-01 21:32:17
【问题描述】:

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...

【问题讨论】:

  • 您使用什么来创建 JSON 响应?还是将它们存储为文件?
  • wordpress 插件名为 json-api

标签: json header getjson


【解决方案1】:
AddType application/json .json

是一种使您的所有*.json 文件以正确的mime 类型发送的简单方法。当然,如果您在诸如 PHP 脚本之类的东西中动态创建它们,那当然是行不通的。在这种情况下,您可以在脚本中添加信息:

<?php
header('Content-Type: application/json');
// ...

【讨论】:

    【解决方案2】:

    您可以使用Firebug's Net 选项卡检查从服务器端发送的标头。它显示了请求和响应的所有标头。

    【讨论】:

      【解决方案3】:

      确保 Content-Type 为 application/json。如果您不确定它们是什么,您可以使用 wget 等检查 http 标头。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2021-07-18
        • 1970-01-01
        • 2017-03-23
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多