new Ajax(baseopt, elementopt, elementSettings)
Ajax constructor.
The Ajax request returns an array of commands encoded in JSON, which is then executed to make any changes that are necessary to the page.
Drupal uses this file to enhance form elements with #ajax['url']
and
#ajax['wrapper']
properties. If set, this file will automatically be
included to provide Ajax capabilities.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
base |
string |
<optional> |
Base parameter of |
element |
HTMLElement |
<optional> |
Element parameter of |
elementSettings |
Drupal.Ajax~elementSettings | Settings for this Ajax object. |
- Source:
Members
(static, constant) AJAX_REQUEST_PARAMETER :string
Request parameter to indicate that a request is a Drupal Ajax request.
Type:
- string
- Default Value:
- _drupal_ajax
- Source:
$form :jQuery
Type:
- Source:
commands :Drupal.AjaxCommands
Type:
- Source:
element :HTMLElement
Type:
- HTMLElement
- Source:
element_settings :Drupal.Ajax~elementSettings
Type:
- Deprecated:
- in drupal:8.5.0 and is removed from drupal:10.0.0. Use elementSettings.
- Source:
- See:
elementSettings :Drupal.Ajax~elementSettings
Type:
- Source:
instanceIndex :bool|number
Type:
- bool | number
- Source:
options :object
Options for the jQuery.ajax function.
Type:
- object
Properties:
Name | Type | Default | Description |
---|---|---|---|
url |
string | Ajax URL to be called. |
|
data |
object | Ajax payload. |
|
beforeSerialize |
function | Implement jQuery beforeSerialize function to call
|
|
beforeSubmit |
function | Implement jQuery beforeSubmit function to call
|
|
beforeSend |
function | Implement jQuery beforeSend function to call
|
|
success |
function | Implement jQuery success function to call
|
|
complete |
function | Implement jQuery success function to clean up ajax state and trigger an error if needed. |
|
dataType |
string | 'json' | Type of the response expected. |
type |
string | 'POST' | HTTP method to use for the Ajax request. |
- Source:
url :string
Processed Ajax URL.
Type:
- string
- Source:
wrapper :string
Type:
- string
- Source:
Methods
beforeSend(xmlhttprequest, options)
Prepare the Ajax request before it is sent.
Parameters:
Name | Type | Description |
---|---|---|
xmlhttprequest |
XMLHttpRequest | Native Ajax object. |
options |
object | jQuery.ajax options. |
- Source:
beforeSerialize(elementopt, options)
Handler for the form serialization.
Runs before the beforeSend() handler (see below), and unlike that one, runs before field data is collected.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
element |
object |
<optional> |
Ajax object's |
options |
object | jQuery.ajax options. |
- Source:
beforeSubmit(formValues, element, options)
Modify form values prior to form submission.
Parameters:
Name | Type | Description |
---|---|---|
formValues |
Array.<object> | Processed form values. |
element |
jQuery | The form node as a jQuery object. |
options |
object | jQuery.ajax options. |
- Source:
error(xmlhttprequest, uri, customMessageopt)
Handler for the form redirection error.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
xmlhttprequest |
object | Native XMLHttpRequest object. |
|
uri |
string | Ajax Request URI. |
|
customMessage |
string |
<optional> |
Extra message to print with the Ajax error. |
- Source:
eventResponse(element, event)
Handle an event that triggers an Ajax response.
When an event that triggers an Ajax response happens, this method will perform the actual Ajax call. It is bound to the event using bind() in the constructor, and it uses the options specified on the Ajax object.
Parameters:
Name | Type | Description |
---|---|---|
element |
HTMLElement | Element the event was triggered on. |
event |
jQuery.Event | Triggered event. |
- Source:
execute() → {object}
Execute the ajax request.
Allows developers to execute an Ajax request manually without specifying an event to respond to.
- Source:
Returns:
Returns the jQuery.Deferred object underlying the Ajax request. If pre-serialization fails, the Deferred will be returned in the rejected state.
- Type
- object
getEffect(response) → {object}
Build an effect object to apply an effect when adding new HTML.
Parameters:
Name | Type | Description | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
response |
object | Drupal Ajax response. Properties
|
- Source:
Returns:
Returns an object with showEffect
, hideEffect
and showSpeed
properties.
- Type
- object
keypressResponse(element, event)
Handle a key press.
The Ajax object will, if instructed, bind to a key press response. This will test to see if the key press is valid to trigger this event and if it is, trigger it for us and prevent other keypresses from triggering. In this case we're handling RETURN and SPACEBAR keypresses (event codes 13 and 32. RETURN is often used to submit a form when in a textfield, and SPACE is often used to activate an element without submitting.
Parameters:
Name | Type | Description |
---|---|---|
element |
HTMLElement | Element the event was triggered on. |
event |
jQuery.Event | Triggered event. |
- Source:
setProgressIndicatorBar()
Sets the progress bar progress indicator.
- Source:
setProgressIndicatorFullscreen()
Sets the fullscreen progress indicator.
- Source:
setProgressIndicatorThrobber()
Sets the throbber progress indicator.
- Source:
success(response, status)
Handler for the form redirection completion.
Parameters:
Name | Type | Description |
---|---|---|
response |
Array.<Drupal.AjaxCommands~commandDefinition> | Drupal Ajax response. |
status |
number | XMLHttpRequest status. |
- Source:
Type Definitions
elementSettings
Settings for an Ajax object.
Type:
- object
Properties:
Name | Type | Attributes | Default | Description | |||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
url |
string | Target of the Ajax request. |
|||||||||||||||||
event |
string |
<optional> <nullable> |
Event bound to settings.element which will trigger the Ajax request. |
||||||||||||||||
keypress |
bool |
<optional> |
true | Triggers a request on keypress events. |
|||||||||||||||
selector |
string |
<nullable> |
jQuery selector targeting the element to bind events to or used with
|
||||||||||||||||
effect |
string |
<optional> |
'none' | Name of the jQuery method to use for displaying new Ajax content. |
|||||||||||||||
speed |
string | number |
<optional> |
'none' | Speed with which to apply the effect. |
|||||||||||||||
method |
string |
<optional> |
Name of the jQuery method used to insert new content in the targeted element. |
||||||||||||||||
progress |
object |
<optional> |
Settings for the display of a user-friendly loader. Properties
|
||||||||||||||||
submit |
object |
<optional> |
Extra data to be sent with the Ajax request. Properties
|
||||||||||||||||
dialog |
object |
<optional> |
Options for |
||||||||||||||||
dialogType |
string |
<optional> |
One of |
||||||||||||||||
prevent |
string |
<optional> |
List of events on which to stop default action and stop propagation. |
- Source: