twitst4tz

twitter statistics web application
Log | Files | Refs | README | LICENSE

test-request-protocols.js (677B)


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