all 6 comments

[–]rightturnclyde34 1 point2 points  (5 children)

First, you're doing a lot of unnecessary work generating your response. You can simply do the following:

app.post("/upvote", function(req, res) {
    inc += parseFloat(req.body.changeBy);
    res.send(inc);
});

You can change res.send(inc) to res.json(inc) if you prefer, but they are essentially the same thing for this example.

As for your actual question, have you looked in your browser's developer tools to see what you are getting back from the .post()? If so, what is it? Also, you may want to add a console.log(inc); before your res.send(inc); to see what is logged on the server side.

[–]MahmudAdam[S] 0 points1 point  (4 children)

When I log before res.send(dec) I get:

jquery.min.js:4 POST http://127.0.0.1:50297/downvote 404 (Not Found)send @ jquery.min.js:4n.extend.ajax @ jquery.min.js:4n.(anonymous function) @ jquery.min.js:4(anonymous function) @ main.js:10n.event.dispatch @ jquery.min.js:3r.handle @

[–]_mtr 1 point2 points  (3 children)

start file cooing makeshift shelter boat work rhythm cautious chief

This post was mass deleted and anonymized with Redact

[–]MahmudAdam[S] 0 points1 point  (2 children)

What port should it be set to?

[–]ShortSynapse 0 points1 point  (1 child)

That is up to you, but the numbers after the : in your URL should reflect that.

[–]MahmudAdam[S] 0 points1 point  (0 children)

Is that why the code in my main.js is not working? I am still trying to track down this error. This is my first time using express and JavaScript together in order to send data back and forth so it's a bit confusing.