4

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~

1
  • Node.js will never listen to html button click event unless you receive that event in client-side JavaScript and toss that to Node.js through AJAX or WebSocket. Commented Oct 1, 2012 at 11:35

2 Answers 2

4

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

Sign up to request clarification or add additional context in comments.

Comments

1

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.