Skip to content

Instantly share code, notes, and snippets.

@acrogenesis
Last active August 29, 2015 14:15
Show Gist options
  • Save acrogenesis/60368b9c504ba15ed72a to your computer and use it in GitHub Desktop.
Save acrogenesis/60368b9c504ba15ed72a to your computer and use it in GitHub Desktop.
Returns timestamp
<html>
<head>
<title>Timestamp</title>
</head>
<script>
var myTimer;
function getTime(){
var xmlhttp;
var span;
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
p = document.createElement("p");
p.innerText = xmlhttp.responseText
document.getElementById("timestamps").appendChild(p);
}
}
xmlhttp.open("GET","http://localhost:4567/",true);
xmlhttp.send();
}
function startGetTime(){
getTime();
myTimer = setInterval(function(){ getTime(); }, 20000);
}
function stopGetTime(){
clearInterval(myTimer);
}
</script>
<body>
<button name="button" onclick="startGetTime();">Start</button>
<button name="button" onclick="stopGetTime();">Stop</button>
<div id="timestamps">
</div>
</body>
</html>
require 'sinatra'
get '/' do
response['Access-Control-Allow-Origin'] = '*'
Time.now.to_s
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment