JavaScript/AJAX page callback
JavaScript/AJAX page callback (handler) is an interim solution for high-performance querying of contents via AJAX/JavaScript for sites running D5 or D6.
By copying the js.php into Drupal's root directory, setting up clean URLs, and adding a Apache RewriteRule (see README) to the .htaccess file, modules are able to quickly query information from Drupal via JavaScript.
Apache bench example:
/index.php?q=js/module_name/callback-id/arg1/arg2: 316 bytes: 2.24 [#/sec]: 446.846 [ms]
/js.php?q=js/module_name/callback-id/arg1/arg2: 316 bytes: 16.84 [#/sec]: 59.371 [ms]This module assumes the path /js to be a generic JavaScript callback handler. The 2nd argument is the name of the implementing module, and the 3rd an internal callback id specified via hook_js().
Each module implementing a JS callback also needs to register a corresponding menu path in hook_menu() to provide fallback functionality when js.php is not available:
<?php
$items[] = array(
'path' => 'js/module_name/callback-id',
'callback' => 'module_name_custom_callback_function',
'type' => MENU_CALLBACK,
);
?>js.php bootstraps to DRUPAL_BOOTSTRAP_PATH and includes common.inc as well as locale.inc. This means that url(), l(), and t() functions are available in callback functions. Theme functions and potentially required functions of other modules are, however, not available. Other required includes and/or modules can be specified in hook_js(), but also loaded manually via drupal_load(). Since the session has been initialized, the global $user object is also available (but not fully loaded).
Please note that js.php does NOT perform access checks like Drupal's menu system. If required, each callback function needs to do this on its own.
Each JS callback function should complete with the following lines, so the callback will work both with and without js.php:
<?php
print drupal_to_js($output);
exit;
?>Dependencies
- None.
Installation
- Please see current README.txt.
Credits
Current maintainers:
This project has been sponsored by:
- UNLEASHED MIND
Specialized in consulting and development of Drupal powered sites, our services include installation, development, theming, customization, and hosting to get you started. Visit http://www.unleashedmind.com for more information.
Releases
| Official releases | Date | Size | Links | Status | |
|---|---|---|---|---|---|
| 5.x-1.0 | 2008-Apr-26 | 9.6 KB | Download · Release notes | Recommended for 5.x | |
