view node_modules/xmlhttprequest/tests/test-request-protocols.js @ 84:a4a9059a3802

local to server
author Rob Canning <rob@foo.net>
date Mon, 28 Jul 2014 18:17:02 +0100
parents cd921abc8887
children
line wrap: on
line source
var sys = require("util")
  , assert = require("assert")
  , XMLHttpRequest = require("../lib/XMLHttpRequest").XMLHttpRequest
  , xhr;

xhr = new XMLHttpRequest();

xhr.onreadystatechange = function() {
  if (this.readyState == 4) {
    assert.equal("Hello World", this.responseText);
    this.close();
    runSync();
  }
};

// Async
var url = "file://" + __dirname + "/testdata.txt";
xhr.open("GET", url);
xhr.send();

// Sync
var runSync = function() {
  xhr = new XMLHttpRequest();

  xhr.onreadystatechange = function() {
    if (this.readyState == 4) {
      assert.equal("Hello World", this.responseText);
      this.close();
      sys.puts("done");
    }
  };
  xhr.open("GET", url, false);
  xhr.send();
}