Skip to content

Instantly share code, notes, and snippets.

@nhunzaker
Last active December 10, 2015 23:59
Show Gist options
  • Save nhunzaker/4513246 to your computer and use it in GitHub Desktop.
Save nhunzaker/4513246 to your computer and use it in GitHub Desktop.
var express = require('express');
var app = express();
var port = process.env.PORT || 9292;
app.get('/', function(req, res) {
res.render('index');
});
app.post('/control/:action', function(req, res) {
var action = req.params.action;
// do something
res.json({ success: true })
});
app.listen(port);
<button data-action="start">Start</button>
<button data-action="stop">Stop</button>
<button data-action="reverse">Reverse</button>
<script>
// Let's assume jquery....
$('button').click(function(e) {
e.preventDefault();
var action = this.getAttribute("data-action")
$.post("/control/" + action, function(data) {
console.log(data);
})
})
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment