function ajax_deliver

×

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/api.elmsln.org/includes/bootstrap.inc).
cis7 ajax.inc ajax_deliver($page_callback_result)
cle7 ajax.inc ajax_deliver($page_callback_result)
elmsmedia7 ajax.inc ajax_deliver($page_callback_result)
icor7 ajax.inc ajax_deliver($page_callback_result)
meedjum_blog7 ajax.inc ajax_deliver($page_callback_result)
mooc7 ajax.inc ajax_deliver($page_callback_result)

Packages and sends the result of a page callback as an Ajax response.

This function is the equivalent of drupal_deliver_html_page(), but for Ajax requests. Like that function, it:

  • Adds needed HTTP headers.
  • Prints rendered output.
  • Performs end-of-request tasks.

Parameters

$page_callback_result: The result of a page callback. Can be one of:

  • NULL: to indicate no content.
  • An integer menu status constant: to indicate an error condition.
  • A string of HTML content.
  • A renderable array of content.

See also

drupal_deliver_html_page()

Related topics

1 call to ajax_deliver()
boxes_footer in sites/all/modules/ulmus/boxes/boxes.module
Implements hook_footer().
10 string references to 'ajax_deliver'
ajax_test_menu in modules/simpletest/tests/ajax_test.module
Implements hook_menu().
devel_themer_menu in sites/all/modules/ulmus/devel_themer/devel_themer.module
Implements hook_menu().
field_collection_menu in sites/all/modules/ulmus/field_collection/field_collection.module
Implements hook_menu().
file_menu in modules/file/file.module
Implements hook_menu().
hook_page_delivery_callback_alter in modules/system/system.api.php
Alters the delivery callback used to send the result of the page callback to the browser.

... See full list

File

includes/ajax.inc, line 464
Functions for use with Drupal's Ajax framework.

Code

function ajax_deliver($page_callback_result) {
  // Browsers do not allow JavaScript to read the contents of a user's local
  // files. To work around that, the jQuery Form plugin submits forms containing
  // a file input element to an IFRAME, instead of using XHR. Browsers do not
  // normally expect JSON strings as content within an IFRAME, so the response
  // must be customized accordingly.
  // @see http://malsup.com/jquery/form/#file-upload
  // @see Drupal.ajax.prototype.beforeSend()
  $iframe_upload = !empty($_POST['ajax_iframe_upload']);

  // Emit a Content-Type HTTP header if none has been added by the page callback
  // or by a wrapping delivery callback.
  if (is_null(drupal_get_http_header('Content-Type'))) {
    if (!$iframe_upload) {
      // Standard JSON can be returned to a browser's XHR object, and to
      // non-browser user agents.
      // @see http://www.ietf.org/rfc/rfc4627.txt?number=4627
      drupal_add_http_header('Content-Type', 'application/json; charset=utf-8');
    }
    else {
      // Browser IFRAMEs expect HTML. With most other content types, Internet
      // Explorer presents the user with a download prompt.
      drupal_add_http_header('Content-Type', 'text/html; charset=utf-8');
    }
  }

  // Print the response.
  $commands = ajax_prepare_response($page_callback_result);
  $json = ajax_render($commands);
  if (!$iframe_upload) {
    // Standard JSON can be returned to a browser's XHR object, and to
    // non-browser user agents.
    print $json;
  }
  else {
    // Browser IFRAMEs expect HTML. Browser extensions, such as Linkification
    // and Skype's Browser Highlighter, convert URLs, phone numbers, etc. into
    // links. This corrupts the JSON response. Protect the integrity of the
    // JSON data by making it the value of a textarea.
    // @see http://malsup.com/jquery/form/#file-upload
    // @see http://drupal.org/node/1009382
    print '<textarea>' . $json . '</textarea>';
  }

  // Perform end-of-request tasks.
  ajax_footer();
}