I want to return JSON from a PHP script.
Do I just echo the result? Do I have to set the Content-Type
header?
As said above:
header('Content-Type: application/json');
will make the job. but keep in mind that :
Ajax will have no problem to read json even if this header is not used, except if your json contains some HTML tags. In this case you need to set the header as application/json.
Make sure your file is not encoded in UTF8-BOM. This format add a character in the top of the file, so your header() call will fail.