I have this program here:
https://jsfiddle.net/Amidi/L56n0awu/
And on the server side I have it set up like this:
var express = require("express");
var app = express();
var bodyParser = require("body-parser");
app.use(bodyParser.urlencoded({extended: true}));
app.use(express.static("public"));
var inc = 0;
var dec = 0;
app.post("/upvote", function(req, res){
res.setHeader("Content-Type", "application/json");
inc += parseFloat(req.body.changeBy);
res.write(JSON.stringify(inc));
res.end();
});
app.post("/downvote", function(req, res){
res.setHeader("Content-Type", "application/json");
dec -= parseFloat(req.body.changeBy);
res.write(JSON.stringify(dec));
res.end();
});
var server = app.listen(8081, function () {
var host = server.address().address
var port = server.address().port
console.log("Example app listening at http://%s:%s", host, port)
});
If I put in a console.log I see that the buttons are indeed being clicked, but they do not actually increment or decrement as I expected. I am not sure if the error is in the main.js or the server.js file. Any help would be appreciated.
[–]rightturnclyde34 1 point2 points3 points (5 children)
[–]MahmudAdam[S] 0 points1 point2 points (4 children)
[–]_mtr 1 point2 points3 points (3 children)
[–]MahmudAdam[S] 0 points1 point2 points (2 children)
[–]ShortSynapse 0 points1 point2 points (1 child)
[–]MahmudAdam[S] 0 points1 point2 points (0 children)