Note. I do not address this issue with Drupal, so I post it here on SO.
We created a Drupal module that should return JSON. For instance. call / foo / json returns JSON. Everything is fine in Chrome. However, Firefox just shows "null".
JSON content is just a PHP array with some information that is populated by a loop
$someArray = array(); foreach(....) { $someArray[] = array("foo" => "bar", ...); } echo json_encode($someArray);
I still know that
- this is not an encoding problem. If I return only one item from
$someArray[0]["some_key"] , Chrome shows "USA" with a Content Length of 5, so I'm sure there are no characters other than ASCII. However, Firefox shows null with a content length of 4. - Doing
wget gives me the correct content with all JSON. Since I trust wget more than the browser, I assume this is not a Drupal / .htaccess problem. - JSON is well-formed according to jsonlint.com, and since the PHP function performs the conversion, I assume it is really well-formed.
- other things, such as permissions (everyone is allowed to connect to the page) or encoding (sending UTF-8), does not change the result.
- This is not related to jQuery / cross-domain since I just want to call the url in the browser and want to see the JSON response.
- On another machine with the same setup (Drupal), the result will be the same.
- I can return JSON from other directories that are not related to Drupal setup. But since I'm just doing
json_encode , I will get around every possible Drupal output, and since wget works, I am not involved with Drupal IMO.
updates according to comments
- An
application/json content type with appropriate encoding information. Changing it to text / html or something else does not change anything. Using both the header and the Drupal function to customize the headers. - I am sure the
null answer is correct, since I tested it with Firebug. ini_set('default_charset', 'UTF-8'); nothing changes, as I am already sending this information to the header.
Answer header from Firefox with Firebug
Cache-Control no-cache, must-revalidate, post-check=0, pre-check=0 Connection Keep-Alive Content-Language en Content-Length 4 Content-Type application/json; charset=utf-8 Date Mon, 03 Sep 2012 12:16:58 GMT Etag "1346674618" Expires Sun, 19 Nov 1978 05:00:00 GMT Keep-Alive timeout=5, max=100 Last-Modified Mon, 03 Sep 2012 12:16:58 +0000 Server Apache/2.2.22 (Ubuntu) X-Powered-By PHP/5.3.10-1ubuntu3.2
Request header
Accept text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 Accept-Encoding gzip, deflate Accept-Language en-us,en;q=0.7,de;q=0.3 Connection keep-alive Cookie has_js=1; respimg_ratio=1; respimg=1000 //Drupal information Host vie.local User-Agent Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:15.0) Gecko/20100101 Firefox/15.0
TL DR
Although Chrome shows the correct (well-formed) JSON output, Firefox (as well as verified in Opera) shows only null even for the simplest string, such as "USA" .
source share