Last active
October 25, 2016 11:48
-
-
Save madr/5e9eb307e7151ff5ebf95f56cb8f3d03 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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