Some administration and debugging modules for Drupal attach their statistics to the end of Drupal rendered pages using PHP's register_shutdown_function function facility. This is great to ensure the output is always available, no matter how badly built the theme being used is.
Examples of modules adding their stats to the footer include the superb Devel package which allows outputting statistics on your database queries (or "Gunk" as its called in the source code), and the Memcache Admin UI module which provides information about the memcache bin usage.
The problem arises when you're using Drupal to output AJAX responses which contain plain text. If your Drupal generated response doesn't have a suitable HTTP header defined for it, then both Devel and Memcache tag on their output to your AJAX response and cause the client-side JavaScript to be very confused, or just fail.
The simple solution is to set a HTTP Header in your custom module before the output. Headers which are recognised by Devel and Memcache vary. Devel recognises
'xml', 'javascript', 'json', 'plain', 'image', 'application', 'csv', and 'x-comma-separated-values', whilst Memcache picks up on 'xml', 'javascript', and 'plain'.
Using the Drupal API add the following before you print your output:
drupal_set_header('Content-Type: text/plain; charset=utf-8');
The Devel module also has an extra switch you can set using $GLOBALS['devel_shutdown'] = FALSE
to suppress the output, however that doesn't cover the Memcache case.
Comments
Worked for me. Thanx
In Drupal 7 you may use http://api.drupal.org/api/drupal/includes!ajax.inc/function/ajax_delive… which adds needed HTTP headers and more related to AJAX.
Even better use the "delivery callback" attribute in your menu_hook() items to change the standard delivery callback to ajax_deliver().
In reply to In Drupal 7 you may use by Bernhard Fürst
Spot on! Saved my headache getting any worse with my custom AJAX callbacks being meddled with by the devel module. Thanks for the explanation just at the right time!