network.js 551 B

12345678910111213141516171819202122
  1. function doGet(url, callback) {
  2. var xhr = new XMLHttpRequest();
  3. xhr.onreadystatechange = function(e) {
  4. if (xhr.readyState === 4) {
  5. var resp = null;
  6. if (xhr.status === 200) {
  7. resp = xhr.response;
  8. try {
  9. resp = JSON.parse(/** @type {string} */ (resp));
  10. } catch (e) {
  11. resp = null;
  12. }
  13. }
  14. callback(xhr.status, resp);
  15. }
  16. };
  17. xhr.open('GET', url, true);
  18. xhr.send(null);
  19. }