Skip to content

Instantly share code, notes, and snippets.

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