Stephen Stephen - 2 years ago 121
Node.js Question

NodeJS Post request using a Button

I don't know if this is possible or not. All the research I've done has shown that it is possible with a form and text input. But anyways, Using NodeJs & Express I want to be able to click a button on my webpage, and once it's clicked, it sends a post request to my Node.JS server.

Simpler way of saying it:
When button is clicked, send info to the server.

Goal I'm trying to achieve:
When button is clicked, it sends some sort of ID/code/anything to turn on a service from my database. (I have yet to learn how db's work so I am just trying to focus on front end.)

Code I have so far:"/send", function(req, res){
var newID = req.body.ID;

<form action="/send" method="POST">
<input type="button" name="newID" placeholder="Button">

Answer Source

For this purposes you should use $.ajax, example:

$('button').on('click', function() {
      type: 'POST',
      url: '/send',
      data: { ID: 'someid' },
      success: function(resultData) {
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download