load

loads data from an external data source.

promise load(string url, [string type,function callback] );

Parameters

urlstringthe data url
typestring(optional) the type of data to load: 'json' (default), 'xml', 'jsarray', 'csv'
callbackfunction(optional) the callback function

Returns

promise"promise" object

Example

$$("mylist").load("data.xml", "xml");

Related samples

Details

Function signatures

The load method can be used with up to three parameters:

  • By default, the data type is set to 'json':
$$("component_id").load("some/path/data.json");
  • You can also pass a callback function:
$$('component_id').load("some/path/data.json", function(text, data, http_request){
  // do something with data.json()
});
  • If you need to specify both the data type and the callback:
$$("component_id").load("some/path/data.xml", "xml", function(text, data, http_request){
  // do something with the data object
});
//or
$$("component_id").load("some/path/data.xml", "xml", {
  error: function(text, data, http_request){
    webix.alert("error");
  },
  success:function(text, data, http_request){
    webix.message("success");
  }
});

Callback

By default, the loading is asynchronous, so you will need to use the callback to trigger some action after loading is finished.

The callback function takes 3 parameters:

  1. The text of the response
  2. The data object of the response
  3. The raw HTTP request object

Return Value

The method returns a Promises/A+ compatible promise object than contains the eventual result of an AJAX request.

Webix uses the Promiz.js library for promises. Learn more at:

Error handlers

The callback can be defined as a combination of error and success functions (you can use only one of them if you want to).

Post and synchronous loading

As the load method doesn't provide direct ability to use post and sync, you can use the parse method instead:

// sync data loading
var result = webix.ajax().sync().get("some.json");
$$("component_id").parse(result.responseText);
// using POST for data loading
var result = webix.ajax().post("mydata.php", "some=value", function (text) {
  $$("component_id").parse(text);
});
See also
Back to top