How to set the correct json headers?

Is there an htaccess way to guarantee the correct headers for my json?

Update: does anyone see something 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 

In particular, it works with jquery getJSON in ie8, ffx, chrome, but not ie7 or ie6 ...

+6
json header getjson
source share
3 answers

You can check the headers sent from the server side using the Firebug Net tab. It shows all the headers for both the request and the response.

+2
source share
 AddType application/json .json 

is an easy way to make all your *.json files sent with the correct mime type. This, of course, does not work if you create them dynamically in something like, say, a PHP script. In this case, you can add the information inside the script:

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

Make sure Content-Type application/json . You can check the http headers with wget and whatnot if you are not sure what it is.

+1
source share

All Articles