使用PHP动态创建内容的JSON mime类型

时间:2012-10-24 00:51:59

标签: php json dynamic

  

可能重复:
  correct HTTP header for json file

我使用以下行设置了php文件的标题:

header('Content-Type', 'application/json');

服务器失败并显示错误消息:

"Tue Oct 23 16:20:09 2012] [error] [client 111.111.111.111] malformed header from script. Bad header=Content-Type: xyz.php, referer:...."

我在网上提出了一些建议,将其添加到.htaccess文件

AddType application/json .json

两者都没有奏效。如果有任何进一步的帮助,我将不胜感激。

2 个答案:

答案 0 :(得分:5)

header('Content-type: application/json');

答案 1 :(得分:1)

注意引号位于header()

的位置

header('Content-type: application/json');