test-request-protocols.js 715 B

1234567891011121314151617181920212223242526272829303132333435
  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. this.close();
  10. runSync();
  11. }
  12. };
  13. // Async
  14. var url = "file://" + __dirname + "/testdata.txt";
  15. xhr.open("GET", url);
  16. xhr.send();
  17. // Sync
  18. var runSync = function() {
  19. xhr = new XMLHttpRequest();
  20. xhr.onreadystatechange = function() {
  21. if (this.readyState == 4) {
  22. assert.equal("Hello World", this.responseText);
  23. this.close();
  24. sys.puts("done");
  25. }
  26. };
  27. xhr.open("GET", url, false);
  28. xhr.send();
  29. }