drupal_json

Definition

drupal_json($var = NULL)
includes/common.inc, line 2322

Description

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.

Parameters

$var (optional) If set, the variable will be converted to JSON and output.

Code

<?php
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);
  }
}
?>
 
 

Drupal is a registered trademark of Dries Buytaert.