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

promisea "promise" object

Example

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

Related samples

Details

The data URL

The url parameter can be set as:

  • string - the path to a file or a script
$$("table").load("some.php");
  • function - the logic that is able to get data and parse them on its own
$$("table").load(function(){
  return webix.ajax(url).then(function(data){
    return data.json();
  });
});
  • object - the loading proxy object
$$("list").load({
  $proxy:true,
  load:function(view, callback, params){
    webix.ajax().bind(view).get(url, params, callback);
  }
});

Function signatures

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

  • By default, the data type is set to 'json', so in case of data in JSON format, it can omitted:
$$("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
If you have not checked yet, be sure to visit site of our main product Webix javascript ui framework and page of javascript pivot product.