Documentation

BX24.callMethod

Use the following call to send a request.

XMLHttpRequest|XDomainRequest 
BX24.callMethod(
    String method,
    Object params[,
    Function callback]
);

The function calls a REST method with specified parameters. The parameters (the params object) are passed as an associative array which will be converted to a POST request string. The possible array values include strings or references to the DOM form elements (see processing files below).

If this method is called prior to calling BX24.init, the request will be queued and postponed.

Example

BX24.callMethod('user.get', 
                {ID: 10}, 
                function(res)
                {
                    if(res.data())
                    {
                        var user = res.data()[0];
                        if (!!user)
                            alert('The name of the user #' + user.ID + ' is ' + user.NAME);
                    }
                });

Processing the request result

The result request handler is a callback function called after the request has been completed; it accepts the following ajaxResult instance:

  • ajaxResult.prototype.data = function() - the function returning the REST method response as an array, an object or a scalar. Refer to the method descriptions for further information.
  • Boolean|String ajaxResult.prototype.error = function() - returns the error description if an error occurred, or false otherwise.

Some methods may return data of substantial size, in which case data is returned in chunks as consequential arrays of 50 items (methods may override this value). Use the following methods to navigate the data chunks:

  • Boolean ajaxResult.prototype.more = function() - returns true if there is still data to fetch. Applicable to methods that return data.
  • Integer ajaxResult.prototype.total = function() - returns the total number of data records. Applicable to methods that return data.
  • Boolean|XMLHttpRequest|XDomainRequest ajaxResult.prototype.next = function([Function cb]) - requests and returns the next data chunk. The default behavior is return data to the same callback function, which can be overridden by passing another callback function as the cb argument.

Example

The following code will return the list of users in screens of 50 records.

BX24.callMethod('user.get', {sort:'ID',order:'ASC'}, function(result) {
        if (result.error())
        {
               alert('Request error: ' + result.error());
        }
         else
        {
                console.log(result.data());
                if (result.more())
                       result.next();
        }
});



User Comments

User comments are not part of official documentation. Use information provided by other users in the comments at your own risk.

The User Comments section is not to be used as a feature discussion board. Only registered users can post comments. Your comment will be visible once it has been approved by the moderator.
© «Bitrix Inc.», 2001-2019, «Bitrix Inc.», 2019