class Api { getAuthors (params, cb) { const xhr = new XMLHttpRequest(); params = Object.entries(params).map(([key, value]) => `${key}=${value}`).join('&'); params = params !== '' ? `&${params}` : ''; xhr.open("GET", `/api/v/1.0/get-authors?response_format=json${params}`, true); xhr.onreadystatechange = function (event) { //console.log(event); if (this.readyState != 4) return; cb(JSON.parse(this.responseText).response); }; xhr.send(); } getMuzic (params, cb) { const xhr = new XMLHttpRequest(); params = Object.entries(params).map(([key, value]) => `${key}=${value}`).join('&'); params = params !== '' ? `&${params}` : ''; xhr.open("GET", `/api/v/1.0/get-muzic?response_format=json${params}`, true); xhr.onreadystatechange = function (event) { //console.log(event); if (this.readyState != 4) return; cb(JSON.parse(this.responseText).response); }; xhr.send(); } createMuzic (author_id, name, data=null, cb) { data = data === null ? undefined : data; const xhr = new XMLHttpRequest(); xhr.open("POST", `/api/v/1.0/create-item?response_format=json`, true); xhr.setRequestHeader('Content-type', 'application/json; charset=utf-8'); xhr.onreadystatechange = function (event) { //console.log(event); if (this.readyState != 4) return; cb(JSON.parse(this.responseText).response); }; xhr.send(JSON.stringify({ type: 'muzic', name, author_id, data })); } } const api = new Api();