- 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) (TODO: no more plain text in current version)
- success(xhr.responseText);
- }
- if (res_json) {
- 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) {