function ajax_render


Error message

User warning: The following module is missing from the file system: theme/theme. For information about how to fix this, see the documentation page. in _drupal_trigger_error_with_delayed_logging() (line 1156 of /var/www/html/elmsln_community/
cis7 ajax_render($commands = array())
cle7 ajax_render($commands = array())
elmsmedia7 ajax_render($commands = array())
icor7 ajax_render($commands = array())
meedjum_blog7 ajax_render($commands = array())
mooc7 ajax_render($commands = array())

Renders a commands array into JSON.


$commands: A list of macro commands generated by the use of ajax_command_*() functions.

Related topics

22 calls to ajax_render()
ajax_deliver in includes/
Packages and sends the result of a page callback as an Ajax response.
ctools_access_ajax_add in sites/all/modules/ulmus/ctools/includes/
AJAX callback to add a new access test to the list.
ctools_access_ajax_delete in sites/all/modules/ulmus/ctools/includes/
AJAX command to remove an access control item.
ctools_access_ajax_edit in sites/all/modules/ulmus/ctools/includes/
AJAX callback to edit an access test in the list.
ctools_ajax_render_error in sites/all/modules/ulmus/ctools/includes/
Send an error response back via AJAX and immediately exit.

... See full list

1 string reference to 'ajax_render'
ajax_test_menu in modules/simpletest/tests/ajax_test.module
Implements hook_menu().


includes/, line 232
Functions for use with Drupal's Ajax framework.


function ajax_render($commands = array()) {
  // Ajax responses aren't rendered with html.tpl.php, so we have to call
  // drupal_get_css() and drupal_get_js() here, in order to have new files added
  // during this request to be loaded by the page. We only want to send back
  // files that the page hasn't already loaded, so we implement simple diffing
  // logic using array_diff_key().
  foreach (array('css', 'js') as $type) {
    // It is highly suspicious if $_POST['ajax_page_state'][$type] is empty,
    // since the base page ought to have at least one JS file and one CSS file
    // loaded. It probably indicates an error, and rather than making the page
    // reload all of the files, instead we return no new files.
    if (empty($_POST['ajax_page_state'][$type])) {
      $items[$type] = array();
    else {
      $function = 'drupal_add_' . $type;
      $items[$type] = $function();
      drupal_alter($type, $items[$type]);
      // @todo Inline CSS and JS items are indexed numerically. These can't be
      //   reliably diffed with array_diff_key(), since the number can change
      //   due to factors unrelated to the inline content, so for now, we strip
      //   the inline items from Ajax responses, and can add support for them
      //   when drupal_add_css() and drupal_add_js() are changed to use a hash
      //   of the inline content as the array key.
      foreach ($items[$type] as $key => $item) {
        if (is_numeric($key)) {
      // Ensure that the page doesn't reload what it already has.
      $items[$type] = array_diff_key($items[$type], $_POST['ajax_page_state'][$type]);

  // Render the HTML to load these files, and add AJAX commands to insert this
  // HTML in the page. We pass TRUE as the $skip_alter argument to prevent the
  // data from being altered again, as we already altered it above. Settings are
  // handled separately, afterwards.
  if (isset($items['js']['settings'])) {
  $styles = drupal_get_css($items['css'], TRUE);
  $scripts_footer = drupal_get_js('footer', $items['js'], TRUE);
  $scripts_header = drupal_get_js('header', $items['js'], TRUE);

  $extra_commands = array();
  if (!empty($styles)) {
    $extra_commands[] = ajax_command_prepend('head', $styles);
  if (!empty($scripts_header)) {
    $extra_commands[] = ajax_command_prepend('head', $scripts_header);
  if (!empty($scripts_footer)) {
    $extra_commands[] = ajax_command_append('body', $scripts_footer);
  if (!empty($extra_commands)) {
    $commands = array_merge($extra_commands, $commands);

  // Now add a command to merge changes and additions to Drupal.settings.
  $scripts = drupal_add_js();
  if (!empty($scripts['settings'])) {
    $settings = $scripts['settings'];
    array_unshift($commands, ajax_command_settings(call_user_func_array('array_merge_recursive', $settings['data']), TRUE));

  // Allow modules to alter any Ajax response.
  drupal_alter('ajax_render', $commands);

  return drupal_json_encode($commands);