This project is not covered by Drupal’s security advisory policy.
This small module provides a simple API and should not be installed unless required by another module, or for your personal development.
Features
- Route XMLHttpRequests to mapped callbacks
- Option to gzip output
- Display status and error messages based on request status
- Message display duration
- Output messages to specific elements, or the default of #ac-messages
- Response headers
- Ability to alter responses via hook_js_response_alter()
- Lock arbitrary requests to a set duration
Examples
This example utilizes AC.request() to delete a piece of content.
The URI of example.com/js/example/delete will call example_js_delete().
// example.js
AC.request('example', 'delete', { 'content_id' : 1 }, function(response){
// AC.checkResponse() will return TRUE when the response was a success, and also manages
// functionality such as displaying messages.
if (AC.checkResponse(response)){
$('#content-1').remove();
}
});
// example.module
function example_js_delete(&$state, $args) {
// Lock the user for 10 seconds regardless of success, to prevent arbitrary requests
$state['lock'] = 10;
// Optionally change the message display wrapper
$state['message_wrapper'] = '#content #message-wrapper';
if ($cid = $args['content_id']){
if (example_delete($cid)){
$state['message'] = t('Request complete');
}
else {
// Tell AC that the request was a failure, and display the error message
$state['status'] = AC_STATUS_ERROR;
$state['message'] = t('Failed to delete !cid.', array('!cid' => $cid));
}
}
}
This module is maintained by Pagebuild. Originally created by Vision Media.
Project information
- Project categories: Developer tools
- Created by tjholowaychuk on , updated
This project is not covered by the security advisory policy.
Use at your own risk! It may have publicly disclosed vulnerabilities.