raspberryGPIOhtmlserver/node_modules/xmlhttprequest/tests/test-request-protocols.js
node_modules/xmlhttprequest/tests/test-request-protocols.jsRaw
1var sys = require("util")
2 , assert = require("assert")
3 , XMLHttpRequest = require("../lib/XMLHttpRequest").XMLHttpRequest
4 , xhr;
5
6xhr = new XMLHttpRequest();
7
8xhr.onreadystatechange = function() {
9 if (this.readyState == 4) {
10 assert.equal("Hello World", this.responseText);
11 this.close();
12 runSync();
13 }
14};
15
16// Async
17var url = "file://" + __dirname + "/testdata.txt";
18xhr.open("GET", url);
19xhr.send();
20
21// Sync
22var runSync = function() {
23 xhr = new XMLHttpRequest();
24
25 xhr.onreadystatechange = function() {
26 if (this.readyState == 4) {
27 assert.equal("Hello World", this.responseText);
28 this.close();
29 sys.puts("done");
30 }
31 };
32 xhr.open("GET", url, false);
33 xhr.send();
34}