I use node.js and express. When I press the button (btnSend), I want to send data to node.js by express (without refresh the page). How do I send data? I want to know the code of node.js
Please help.
Thanks for the advice.
<form action="/Send" method="post">
Username:
<input type="text" name="user" id="txtUser" />
<input type="submit" value="Submit" id="btnSend" />
</form>
You'll need a client side javascript library to do an ajax request, like jQuery. node.js is server side.
in jQuery, you can do it like this:
$("form").submit(function(e){
e.preventDefault();
$.post('/some-page', $(this).serialize(), function(data){
//do something here with json data returned from server.
});
});