diff options
author | Steven Wittens <steven@10.no-reply.drupal.org> | 2007-06-22 08:46:16 +0000 |
---|---|---|
committer | Steven Wittens <steven@10.no-reply.drupal.org> | 2007-06-22 08:46:16 +0000 |
commit | 569ede574f2db14d7359b42e1ccbf5772a4554fb (patch) | |
tree | fadd967fb5610aacf078b562a29f5728f23a710d /includes | |
parent | fe8b35f52778b63b96c969da27d2929beee8c1b9 (diff) | |
download | brdo-569ede574f2db14d7359b42e1ccbf5772a4554fb.tar.gz brdo-569ede574f2db14d7359b42e1ccbf5772a4554fb.tar.bz2 |
#115139: Add centralized json handler (and send text/javascript content-type header).
Diffstat (limited to 'includes')
-rw-r--r-- | includes/common.inc | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/includes/common.inc b/includes/common.inc index 9b4264f49..c371d40d8 100644 --- a/includes/common.inc +++ b/includes/common.inc @@ -2123,6 +2123,24 @@ function drupal_to_js($var) { } /** + * Return data in JSON format. + * + * This function should be used for JavaScript callback functions returning + * data in JSON format. It sets the header for JavaScript output. + * + * @param $var + * (optional) If set, the variable will be converted to JSON and output. + */ +function drupal_json($var = NULL) { + // We are returning JavaScript, so tell the browser. + drupal_set_header('Content-Type: text/javascript; charset=utf-8'); + + if (isset($var)) { + echo drupal_to_js($var); + } +} + +/** * Wrapper around urlencode() which avoids Apache quirks. * * Should be used when placing arbitrary data in an URL. Note that Drupal paths |