Last active
December 10, 2015 23:59
-
-
Save nhunzaker/4513246 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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