Skip to content

Instantly share code, notes, and snippets.

@madr madr/hijax.js
Last active Oct 25, 2016

Embed
What would you like to do?
(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
You can’t perform that action at this time.