我不熟悉node.js,但我想:
*检索从输入表格输入的数据 *通过socket.io发送数据 *接收快递app.js上的数据 保存数据ia变量然后将数据插入mysqldb
我理解发出消息但不确定如何通过发送表单数据。
我尝试过,但它不会发出表单数据。
HTML表单块代码:
<form id="form">
First name <br>
<input type="text" name="firstname" id="fn">
<br>
Mid name <br>
<input type="text" name="Midname" id="mn">
<br>
Last name <br>
<input type="text" name="lastname" id="ln">
<br>
Email <br>
<input type="text" name="Email" id="email">
<br>
password <br>
<input type="text" name="password" id="pass">
<br>
secretQuestion <br>
<input type="text" name="secretQuestion" id="sq">
<br><br>
<input type="submit" value="Submit">
</form>
Stroring data register.js
var socket = io.connect('http://localhost:3000');
socket.on('connect', function(data) {
socket.emit('join', 'Hello World from client');
$('form').submit(function(event){
event.preventDefault();
socket.emit('pers_info', {
firstname: $('#fn').val(),
Midname: $('#mn').val(),
lastname: $('#ln').val(),
Email: $('#email').val(),
password: $('#pass').val(),
secretQuestion: $('#sq').val()
});
});
});
服务器端
io.sockets.on('connection', function(client) {
console.log('Client connected...');
client.on('join', function(data) {
console.log(data); });
client.on('pers_info', function(pers_info) {
console.log(pers_info); });
});