servant/servant-js/examples/www/vanilla/index.html

40 lines
1.0 KiB
HTML

<html>
<head>
<title>Servant: counter</title>
<style>
body { text-align: center; }
#counter { color: green; }
#inc { margin: 0px 20px; background-color: green; color: white; }
</style>
</head>
<body>
<h1>Vanilla version</h1>
<span id="counter">Counter: 0</span>
<button id="inc">Increase</button>
<script src="api.js" type="text/javascript"></script>
<script type="text/javascript">
window.addEventListener('load', function() {
// we get the current value stored by the server when the page is loaded
getCounter(updateCounter, alert);
// we update the value every 1sec, in the same way
window.setInterval(function() {
getCounter(updateCounter, alert);
}, 1000);
});
function updateCounter(response)
{
document.getElementById('counter').innerHTML = 'Counter: ' + response.value;
}
// when the button is clicked, ask the server to increase
// the value by one
document.getElementById('inc').addEventListener('click', function() {
postCounter(updateCounter, alert);
});
</script>
</body>
</html>