Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I pass form data over a websocket? (socket.io)

<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?

like image 608
fancy Avatar asked May 29 '11 14:05

fancy


1 Answers

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);
like image 120
onteria_ Avatar answered Oct 12 '22 23:10

onteria_