、有两种办法,一种是表单提交,一种是ajax方式提交。

1、form提交

   在前台模板文件上写:

 <form action="/reg" method="get">
<input type="text" />
<input type="password" />
<input type="submit" />
</form

   index.js添加一个路由规则:

 router.get('/reg',(req,res) => {
//req,浏览器发送给服务器的数据保存在这里
//参数1:数据库代码 参数2:动态值 参数3:回调
sql('insert into `user` (`id`,`username`,`password`) values (0,?,?)',[req.query.name,req.query.password],(err,result) => {
if(err){
console.log('[INSERT ERROR] - ',err.message);
return;
}
res.json({
success : '[INSERT SUCCESS] - '
});
});
});

2、ajax提交

  (1)先引入jQuery;

(2)前台模板文件写:

     <input type="text" name="name" class="name" />
<input type="password" name="password" class="psw" />
<input type="submit" class="submit" />
<script src="/jquery.js"></script>
<script>
$('.submit').click(function () {
$.ajax({
url : '/reg',
type : 'get',
data : {
name : $('.name').val(),
password : $('.psw').val()
},
success : function (data) {
            console.log(data);
}
});
});
</script>

最新文章

  1. asp.net timer viewstate
  2. 修改BIND9实现TCP DNS
  3. Android 项目实战--手机卫士(实现splash)
  4. 【leetcode】Substring with Concatenation of All Words (hard) ★
  5. 由case 和 break 引发的思考
  6. OpenJudge计算概论-找最大数序列
  7. java集合 collection-list-LinkedList
  8. 谋哥:App排行榜的秘密
  9. java笔记8之选择结构IF
  10. 帝国cms7.0调用指定栏目,指定顺序排列
  11. Oracle行转列实例
  12. How to find variable is empty in shell script
  13. Selenium也是一个用于Web应用程序测试的工具
  14. css hack总结
  15. C#杂记-简化的初始化
  16. vim : 依赖: vim-common (= 2:7.3.429-2ubuntu2) 但是 2:7.3.429-2ubuntu2.1 正要被安装
  17. Codeforces | CF1000B 【Light It Up】
  18. ReentrantLock可重入锁的理解和源码简单分析
  19. 7.Python 正则表达式学习笔记
  20. 【IT笔试面试题整理】不用加减乘除做加法

热门文章

  1. Web前端和Web后端的区分
  2. MYSQL批量导入数据报:[Err] 2006 - MySQL server has gone away 解决方法
  3. 怎样才算精通Linux
  4. Leetcode之二分法专题-154. 寻找旋转排序数组中的最小值 II(Find Minimum in Rotated Sorted Array II)
  5. 18_init 函数的使用
  6. DEVOPS基础
  7. SDU暑期集训排位(2)
  8. codeforces 701 E. Connecting Universities(树+ 边的贡献)
  9. codeforces 486 E. LIS of Sequence(dp)
  10. 题解 UVA12716 GCD等于XOR GCD XOR