Repositorio del curso CCOM4030 el semestre B91 del proyecto Artesanías con el Instituto de Cultura

test-request-protocols.js 677B

1234567891011121314151617181920212223242526272829303132
  1. var sys = require("util")
  2. , assert = require("assert")
  3. , XMLHttpRequest = require("../lib/XMLHttpRequest").XMLHttpRequest
  4. , xhr;
  5. xhr = new XMLHttpRequest();
  6. xhr.onreadystatechange = function() {
  7. if (this.readyState == 4) {
  8. assert.equal("Hello World", this.responseText);
  9. runSync();
  10. }
  11. };
  12. // Async
  13. var url = "file://" + __dirname + "/testdata.txt";
  14. xhr.open("GET", url);
  15. xhr.send();
  16. // Sync
  17. var runSync = function() {
  18. xhr = new XMLHttpRequest();
  19. xhr.onreadystatechange = function() {
  20. if (this.readyState == 4) {
  21. assert.equal("Hello World", this.responseText);
  22. sys.puts("done");
  23. }
  24. };
  25. xhr.open("GET", url, false);
  26. xhr.send();
  27. }