Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 25 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,35 +34,36 @@ module (which in turn is compatible to the API defined by the
In addition, the exposed `XMLHttpRequest` object also has a
`debug` flag for controlling debug messages and there is a `CookieJar` object exposed by the module which
grants access to the cookie jar:

var fs = require("fs");
var xhrc = require("./xmlhttprequest-cookie");
var XMLHttpRequest = xhrc.XMLHttpRequest;
var CookieJar = xhrc.CookieJar;

if (fs.existsSync("./sample.db"))
CookieJar.load(fs.readFileSync("./sample.db", { encoding: "utf8" }));

var get = function (url, complete) {
var xhr = new XMLHttpRequest();
xhr.debug = true;
xhr.onreadystatechange = function() {
if (xhr.readyState === 4) {
console.log("body length: " + this.responseText.length);
complete(xhr);
}
};
xhr.open("GET", "https://github.com/rse/");
xhr.send();
```js
var fs = require("fs");
var xhrc = require("./xmlhttprequest-cookie");
var XMLHttpRequest = xhrc.XMLHttpRequest;
var CookieJar = xhrc.CookieJar;

if (fs.existsSync("./sample.db"))
CookieJar.load(fs.readFileSync("./sample.db", { encoding: "utf8" }));

var get = function (url, complete) {
var xhr = new XMLHttpRequest();
xhr.debug = true;
xhr.onreadystatechange = function() {
if (xhr.readyState === 4) {
console.log("body length: " + this.responseText.length);
complete(xhr);
}
};
xhr.open("GET", "https://github.com/rse/");
xhr.send();
};

get("https://github.com/rse/", function (xhr) {
console.log("body: " + xhr.responseText.substr(0, 100));
get("https://github.com/rse/", function (xhr) {
console.log("body: " + xhr.responseText.substr(0, 100));
get("https://github.com/rse/", function (xhr) {
console.log("body: " + xhr.responseText.substr(0, 100));
fs.writeFileSync("./sample.db", CookieJar.save(), { encoding: "utf8" });
});
fs.writeFileSync("./sample.db", CookieJar.save(), { encoding: "utf8" });
});
});
```

See Also
--------
Expand Down