adapter.js 889 B

1234567891011121314151617181920212223242526272829
  1. var adapter = {
  2. server_url: "",
  3. responseJson: {},
  4. onset: function() {},
  5. onget: function() {},
  6. setter: function () {
  7. xhr = new XMLHttpRequest();
  8. xhr.open('GET', this.server_url + '/set/' + encodeURIComponent(JSON.stringify(this.onset())));
  9. xhr.onload = function () {
  10. console.log(xhr.responseText);
  11. };
  12. xhr.send();
  13. },
  14. getter: function () {
  15. var self = this;
  16. var xhr = new XMLHttpRequest();
  17. xhr.open('GET', this.server_url + '/get');
  18. xhr.onload = function () {
  19. try {
  20. var response = JSON.parse(this.responseText);
  21. self.responseJson = response;
  22. self.onget();
  23. } catch (err) {
  24. console.warn("json could not be parsed:", err, this.responseText);
  25. }
  26. };
  27. xhr.send();
  28. },
  29. };