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.

32 lines
677 B

4 years ago
  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. }