-// data, error: optional
-export function ajax(url, method, data, success, error) {
- let xhr = new XMLHttpRequest();
- if (data === undefined || typeof data === "function") {
- //no data
- error = success;
- success = data;
- data = {};
- }
- if (!success) success = () => {}; //by default, do nothing
- if (!error)
- error = errmsg => {
- alert(errmsg);
+// TODO: use this syntax https://stackoverflow.com/a/29823632 ?
+// data, success, error: optional
+export function ajax(url, method, options) {
+ options = options || {};
+ const data = options.data || {};
+ // By default, do nothing on success and print errors:
+ if (!options.success)
+ options.success = () => {};
+ if (!options.error) {
+ options.error = (errmsg) => {
+ alert(store.state.tr[errmsg] || errmsg);