BX.ajax.runComponentAction
BX.ajax.runComponentAction(component, action[, config])
BX.ajax.runComponentAction is a method for launching ajax actions in the component that returns BX.Promise. In case the csrf token has expired, it will attempt to restore it (only one attempt is made) and repeat the query. If receives query from server, which has status not equal to success
- promis is rejected.
Parameters
Parameter | Description | Available from version |
---|---|---|
component {string} | Full component name to send the query. For example, bitrix:main.post.form or vendor:example. | |
action {string} | Action to be launched. For example, greet. | |
config {Object} | Parameters:
|
In case the response won't contain the keys data and status, the query will be processed with the Network Error.
Example
Suppose, we make an ajax query to component vendor:example taken from example. And trigger the greet action.
BX.ajax.runComponentAction('vendor:example', 'greet', { mode: 'class', //this means that we want to trigger action from class.php data: { person: 'Hero!' //data will be automatically mapped to method parameters }, analyticsLabel: { viewMode: 'grid', filterState: 'closed' } }).then(function (response) { console.log(response); /** { "status": "success", "data": "Hi Hero!", "errors": [] } **/ }, function (response) { //here the location to receive all responses with status !== 'success' console.log(response); /** { "status": "error", "errors": [...] } **/ });
© «Bitrix24», 2001-2024