drupal_json($var = NULL)
drupal/includes/common.inc, line 2782
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.
$var (optional) If set, the variable will be converted to JSON and output.
| Name | Description |
|---|---|
| Input validation | Functions to validate user input. |
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);
}
}