Skip to content

Instantly share code, notes, and snippets.

@madr
Last active October 25, 2016 11:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save madr/5e9eb307e7151ff5ebf95f56cb8f3d03 to your computer and use it in GitHub Desktop.
Save madr/5e9eb307e7151ff5ebf95f56cb8f3d03 to your computer and use it in GitHub Desktop.
(function (g) {
"use strict";
var hijax;
hijax = function (method, uri, data, onSuccess, onError) {
var client = new XMLHttpRequest();
if (onError == undefined) {
onError = function (status, response) {
alert('you have been found guilty of being in league with the devil ' +
'and of having used heathen and forbidden rituals.');
console.log(status);
console.log(response);
}
}
client.open(method, uri, true);
if (method === 'POST') {
client.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
client.setRequestHeader("Content-length", data.length);
client.setRequestHeader("Connection", "close");
}
client.onload = function () {
if (client.status >= 200 && client.status < 400) {
onSuccess(client.responseText);
} else {
onError(client.status, client.responseText);
}
};
client.send(data);
};
g.hijax = hijax;
}(this));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment