Note: I'm not considering this is Drupal problem so I post it here on SO.
We created a Drupal module that is supposed to return JSON. E.g. calling /foo/json returns the JSON. This is all fine in Chrome. However, Firefox just shows "null".
The contents of the JSON is simply a PHP array with some information that gets populated with a loop
$someArray = array();
foreach(....) {
$someArray[] = array("foo" => "bar", ...);
}
echo json_encode($someArray);
So far, I know that
$someArray[0]["some_key"]
, Chrome shows "USA"
with a Content Length
of 5, so I am sure that there is not a single non-ASCII character. However, Firefox shows null
with a Content Length of 4.wget
gives me the correct content with all the JSON. Since I trust wget more than the browser, I assume that it is not a Drupal/.htaccess issue.json_encode
, I bypass every possible output by Drupal and since wget
works I it's not related to Drupal IMO.updates according to comments
application/json
with proper encoding information. Changing it to text/html or something else doesn't change anything. Using both header
as well as the Drupal function for setting headers.null
repsonse is correct, since I inspected it with Firebug.ini_set('default_charset', 'UTF-8');
doesn't change anything since I already submit this information within the header.Response 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
While Chrome shows correct (well-formed) JSON output, Firefox (and also tested in in Opera) only show null
even for simplest string like "USA"
.
The problem was that Firefox, somehow, was not sending the correct language to the server. I don't know if via cookies or within the headers. Since I used language aware filtering for the output, the output was never returned.
So disabling the language filter solved the problem. I have no idea why Firefox had issues with the language but this solved the problem.