Documentation

BX.ajax

XMLHttpRequest BX.ajax(
     object params
);

Low-level function to send ajax queries. The format of the params object:

{
      url: query URL
      method: GET|POST
      data: POST-data to be sent (string or an object)
      dataType: html|json|script – data of which type is provided in the response
      timeout: 60 – query timeout in seconds
      async: true|false – specifies if the query is asynchronous or not
      processData: true|false – specifies if the data should be processed momentarily
      scriptsRunFirst: false|true – specifies if all found scripts must be executed before passing the content to a handler, or only those scripts, which tags have the 'bxrunfirst' attribute
      emulateOnload: true|false – specifies if the 'BX.ajax.onload_495864' event must be emulated for loaded scripts
      start: true|false – specifies if the query sent sent immediately or it will be launched manually
      cache: true|false – If false, an arbtrary line will the added to the URL parameter, to avoid the browser caching
      onsuccess: result handler function 
      onfailure: error handler function 
}

The function returns a link to the XMLHttpRequest object, which is used to send the query. Onsuccess handler will be called if the query is successful. Query's result will be the parameter. If the processData parameter is specified as true, the handling will depend on the type of data as follows:

  • html: result will be cleared from js-code. The code will be executed after the data is passed to the handler. Before the data is passed, all scripts with 'bxrunfirst' attribute will be executed - or all the scripts will be executed if the 'scriptsRunFirst' parameter is specified as 'true';
  • script: the retrieved result will be passed to the handler and executed. Which script is run first - is defined by the 'scriptsRunFirst' parameter
  • json: the result will be interpreted as description of the object in .json format. The handler will receive the object.

If the library to handle the localStorage (core_ls) is connected, then, aside form the listed parameters, the following parameters can be used:

  • lsId – string identifier for pass the query data between different tabs;
  • lsTimeout – query data timeout
  • lsForce - false|true

Those parameters are intended for interfaces that constantly request server to receive data. In this case, the request's data will be saved in the localStorage, and if the request with the same lsId is made in any tab of the current browser, then instead of an executed request, the handler will receive data, saved in localStorage. Accordingly, lsTimeout must be a little less than request sending interval. lsForce parameter allows to forcibly send request and bypass the data availability check in localStorage and update this data.



© «Bitrix24», 2001-2024
Up