Skip to content

Instantly share code, notes, and snippets.

@banthar
Last active March 12, 2016 12:19
Show Gist options
  • Save banthar/6ea66777ca2309fe2a22 to your computer and use it in GitHub Desktop.
Save banthar/6ea66777ca2309fe2a22 to your computer and use it in GitHub Desktop.
<html>
<head>
<script>
function put(data, callback) {
request("PUT", "https://api.myjson.com/bins/4wq17", JSON.stringify(data), callback)
}
function get(callback) {
request("GET", "https://api.myjson.com/bins/4wq17", null, callback)
}
function request(method, url, data, callback) {
var request = new XMLHttpRequest();
request.onload = function(e) {
if(callback){
callback(JSON.parse(e.target.response));
}
}
request.onerror = function(e) {
console.log(e);
}
request.open(method, url, true);
request.setRequestHeader("Content-type", "application/json; charset=utf-8");
request.send(data);
}
get(function(data){
var n = Date.now()+""
data.push(navigator.userAgent)
put(data, null);
})
</script>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment