- if (!success)
- success = () => {}; //by default, do nothing
- if (!error)
- error = errmsg => { alert(errmsg); };
- xhr.onreadystatechange = function() {
- if (this.readyState == 4 && this.status == 200)
- {
- let res_json = "";
- try {
- res_json = JSON.parse(xhr.responseText);
- } catch (e) {
- // Plain text (e.g. for rules retrieval)
- return success(xhr.responseText);
- }
- if (!res_json.errmsg && !res_json.errno)
- success(res_json);
- else
- {
- if (!!res_json.errmsg)
- error(res_json.errmsg);
- else
- error(res_json.code + ". errno = " + res_json.errno);
- }
- }
- };
-
- if (["GET","DELETE"].includes(method) && !!data)
- {