<form name="input" action="">
<input type="text" name="say" />
<input type="submit" value="send" />
</form>
I want to send the data in this form to the server via web sockets, i'm using socket.io.
What is the best way to achieve this?
You'd need to use .serialize() on the form like so:
var formdata = $('form').serialize();
Then pass that over the websocket. On the node.js side, you can get a JS object back by using querystring.parse:
var querystring = require('querystring');
// Data is the data received from the client
var result = querystring.parse(data);
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