Web framework.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

utils.js 731B

12345678910111213141516171819202122232425262728293031323334
  1. function request(method, path, payload, cb) {
  2. var xhr = new XMLHttpRequest();
  3. xhr.open(method, path);
  4. xhr.overrideMimeType("text/plain; charset=x-user-defined");
  5. xhr.send(payload);
  6. xhr.addEventListener("load", function() {
  7. if (cb)
  8. cb(null, xhr.responseText);
  9. });
  10. xhr.addEventListener("abort", function() {
  11. if (cb)
  12. cb(new Error("Aborted"));
  13. });
  14. xhr.addEventListener("error", function() {
  15. if (cb)
  16. cb(new Error("Error"));
  17. });
  18. return xhr;
  19. }
  20. function get(path, cb) {
  21. return request("GET", path, null, cb);
  22. }
  23. function post(path, payload, cb) {
  24. return request("POST", path, payload, cb);
  25. }
  26. window.$$ = document.querySelector.bind(document);
  27. window.request = request;
  28. window.get = get;
  29. window.post = post;