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.


Parameter Description Available from version
component {string} Full component name to send the query. For example, or vendor:example.
action {string} Action to be launched. For example, greet.
config {Object} Parameters:
  • mode {string} Available value is either class, or ajax:
    class - action launch inside class.php,
    ajax - action launch inside ajax.php
  • data {Object|FormData} Object with data to be sent in query body с данными. The same as in BX.ajax.
  • json {Object} - object with data to be passed in query body. Has specified contentType: application/json, and controllers can access original JSON which allows to conveniently handle numerals and empty values.
  • navigation {Object} - page navigation object.
    • page {number} - page number. Count starts from 1.
  • signedParameters {string} Optional. This is string with signed parameters. Generated by the method getSignedParameters()
  • analyticsLabel {string|Object} Optional parameter is used as tag for analytics hits.
  • method {string} Optional. By default, POST.

In case the response won't contain the keys data and status, the query will be processed with the Network Error.


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) {
		"status": "success", 
		"data": "Hi Hero!", 
		"errors": []
}, function (response) {
	//here the location to receive all responses with status !== 'success'
		"status": "error", 
		"errors": [...]

© «Bitrix24», 2001-2024