There is a test application written in Node.JS

var express = require('express'); var app = express(); app.post('/', function (req, res) { getClick(); }); app.listen(3000); function getClick() { console.log('Клик получен'); } 

As you can see, it catches a click from the site and notifies it in the console. Click caught like this

  $('#button').click(function() { event.preventDefault(); $.ajax({ type: 'POST', url: 'http://localhost:3000/' }); }); 

The question is as follows. How to send a response about getting a click not to the console but back to the page from which the click was sent?

  • I do not understand people who minus the question. If he seems idiotic to you, can you answer? What is wrong with you? - Senbonzakuraa

2 answers 2

Something like this:

 var express = require('express'); var app = express(); app.post('/', function (req, res) { req.json({handled: true}); }); app.listen(3000); 
 $('#button').click(function() { event.preventDefault(); $.ajax({ type: 'POST', url: 'http://localhost:3000/', dataType: 'json', success: function (data) { console.log(data) } }); }); 

    On the server side:

     app.post('/', function (req, res) { getClick(res); }); function getClick(res) { res.send('Клик получен'); } 

    On the client:

     $('#button').click(function(event) { event.preventDefault(); $.ajax({ type: 'POST', url: 'http://localhost:3000/', success: function(data) { console.log(data); // <- "Клик получен" } }); });