Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Detecting an html button click with node.js?

Tags: node nodejs html

Detecting an html button click with node.js?

Problem

I'm quite new to node.js, so my apologies if this is a potentially stupid question. I'm aware that when a new page is requested, it triggers a data event, which node can then handle accordingly; on my current project though, I have an html button that triggers a few events, but does not redirect the page. Because of this, node isn't recognizing that this is occurring. Is there any way for me to detect this? Or even, as a workaround, is there any way to call one of my node functions from the javascript embedded in the web page?

Thanks~

Problem courtesy of: Ari

Solution

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

this has nothing to do with clientside ui events, for example a click event on a button.

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

for ajax requests with jquery : jquery $.ajax documentation

a popular websockets implementation for node.js is socket.io

Solution courtesy of: supernova

Discussion

View additional discussion.



This post first appeared on Node.js Recipes, please read the originial post: here

Share the post

Detecting an html button click with node.js?

×

Subscribe to Node.js Recipes

Get updates delivered right to your inbox!

Thank you for your subscription

×