Is there a way to detect a button press with Node.JS? I want to run a function when a certain button is pressed. If possible, preferably without Socket.IO.
1 Answer
clientside:
$('button').click(function () {
$.post('/thing', {data: 'blah'}, function (data) {
console.log(data);
});
}, 'json');
serverside:
var express = require('express');
var bodyParser = require('body-parser');
var app = express();
app.use(bodyParser.urlEncoded());
app.post('/thing', function (req, res, next) {
var data = myFunction(req.body);
res.json(data);
});
1 Comment
anonmous
Works, but it only works about 6 times then you have to refresh.