Having found the html button, click node.js?

I'm new to node.js, so apologize if this is a potentially stupid question. I know that when a new page is requested, it fires a data event that the node can handle accordingly; in my current project, however, I have an html button that fires several events but does not redirect the page. Because of this, node does not recognize that this is happening. Is there any way to detect this? Or even, as a workaround, is there a way to call one of my node functions from javascript embedded in a web page?

Thanks ~

+4
source share
2 answers

you are mixing two different things, the data event in the node you are talking about is triggered because the network connection is established when you point the browser to your site, the data is received and sent from the client to the server and back.

this has nothing to do with client ui events, such as the click event on a button.

if you want node to recognize a click on your button, you need to send something to the server, you can either use the form, or issue an ajax request, or use websites.

for ajax requests with jquery: jquery $ .ajax documentation

popular websockets implementation for node.js socket.io

+3
source

If you want to call something in Node from the client side, you can use socket.io to transfer events to Node. Then catch these events and return the correct data to the client. See socket.io How to Use .

+1
source

Source: https://habr.com/ru/post/1437082/


All Articles