- Issue created by @bburg
It may be a bit late in the D7 module lifespan here, but I'm running into an issue that popped up after I retro-fitted cache tagging on a D7 site. This could very well be caused by a combination of custom modules and configuration already on this site.
JSON output is not displayed on the initial page load. Instead, a blank page is returned with a 200 HTTP status code. On subsequent page loads, the JSON output is displayed as expected when served from the cache. Adding a unique GET parameter to bypass the cache results in a blank page again.
After investigating the issue and testing various solutions, it was found that adding ob_end_flush(); at the end of the views-views-json-style-simple.tpl.php file, just before the drupal_page_footer(); and exit; lines, resolves the issue.
Here's the relevant part of the modified views-views-json-style-simple.tpl.php file:
drupal_add_http_header("Content-Type", "$content_type; charset=utf-8");
print $json;
ob_end_flush(); // Added this line.
drupal_page_footer();
exit;
It's unclear why the issue occurs, but it seems to be related to output buffering. Adding ob_end_flush(); ensures that the output buffer is flushed and the JSON content is sent to the browser on the initial page load.
Active
1.0
Code