I have a problem. I want to make server do something after clicking on button. This is my HTML code:
<input name="like" id="like" value="Like" type="submit" />
<script>
$('like').click(function(){
$.post('/test')
});
</script>
and this is my server-side code:
app.post('/test', function (req, res) {
console.log('works');
});
And it doesn't work.
In the Elements tray, click Form Elements and drag a Submit button onto your page. In the Button Settings tab of the Properties panel, set the button mode to Trigger. Go to the Actions and Events tab of the Properties panel, and select Add New Action. Click Done.
Node, Ajax and JavaScript integration Save the index. html file and refresh the web browser. Uploads to Node. js will go through Ajax, and thus create a full JavaScript file uploader with JavaScript running both on the client and the server.
The jQuery. post( url, [data], [callback], [type] ) method loads a page from the server using a POST HTTP request. data − This optional parameter represents key/value pairs or the return value of the . serialize() function that will be sent to the server.
Your problem is here, you have forgotten the #
for targeting element by id, so click would never be invoke.
$('#like').click(function(){
$.post('/test');
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With