var adapter = { server_url: "", responseJson: {}, onset: function() {}, onget: function() {}, setter: function () { xhr = new XMLHttpRequest(); xhr.open('GET', this.server_url + '/set/' + encodeURIComponent(JSON.stringify(this.onset()))); xhr.onload = function () { console.log(xhr.responseText); }; xhr.send(); }, getter: function () { var self = this; var xhr = new XMLHttpRequest(); xhr.open('GET', this.server_url + '/get'); xhr.onload = function () { try { var response = JSON.parse(this.responseText); self.responseJson = response; self.onget(); } catch (err) { console.warn("json could not be parsed:", err, this.responseText); } }; xhr.send(); }, };