//处理客户post请求
//*1:加载相应模块 http express querystring
//*2:创建web服务器
//*3:监听端口8080
const http = require("http");
const express = require("express");
const qs = require("querystring");

var app = express();
var server = http.createServer(app);
server.listen(8080);

//16:35--16:45
//*4:创建表单 public/9/index.html [用户名密码]
//*5:添加 jquery代码提交表单内容 post
//*6:添加 get请求 /index /jquery
app.get("/",(req,res)=>{
res.sendFile(__dirname+"/public/9/index.html");
});
app.get("/jquery",(req,res)=>{
res.sendFile(__dirname+"/public/9/jquery-1.11.3.js");
});

//7:接收post请求,获了用户数据
app.post("/user",(req,res)=>{
//接收客户端请求主体数据
req.on('data',(buf)=>{
console.log(buf);
console.log(buf.toString());
var obj = qs.parse(buf.toString());
console.log(obj.uname);
console.log(obj.upwd);
res.send("<h1>ok</h1>");
});
});

html中配合代码

<script>
$(function(){

$("#btn").click(function(){
$.ajax({
type:"POST",
url:'/user',
data:{
uname:$("#uname").val(),
upwd:$("#upwd").val()
},
success:function(data){
console.log("服务器端返回数据:"+data);
}

});

});

});

</script>

最新文章

  1. SwipeRefreshLayout嵌套ScrollView包裹复杂头布局和RecyclerView
  2. c#动态调用Webservices
  3. jQuery ui autocomplete下拉列表样式失效解决,三种获取数据源方式,
  4. C# sogou地图API应用总结(二)
  5. PHP学习之[第02讲]PHP5.4 Apache Mysql 搭配与多站点配置详解
  6. java笔录---反射机制(1)
  7. 你不知的DOM编程
  8. JavaScript数据结构与算法(七) 双向链表的实现
  9. document.body.scrollTop和document.documentElement.scrollTop 以及值为0的问题
  10. 自学Python第一天
  11. git冲突Please move or remove them before you can merge
  12. Failed to create Accelerated Display. Please check the display hardware and drivers meet the minimum requirements.
  13. 【问题与解决】showModalDialog is not defined 的解决方案
  14. 移动前端开发和 Web 前端开发的区别
  15. 马凯军201771010116《面向对象程序设计(java)》第三周学习总结
  16. 选择 Java 编写 iOS 与 安卓 App的八大理由
  17. Qbot回归,已感染5.4万台计算机
  18. 状态模式c#(状态流转例子吃饭)
  19. 2D平面中关于矩阵(Matrix)跟图形变换的讲解
  20. Python生成器/推导式/生成器表达式

热门文章

  1. WebService(基于AXIS的WebService编程)
  2. go标准库的学习-crypto/rand
  3. Intellij Idea免费激活方法(转)
  4. Qt+QGIS二次开发:读取矢量元素及其属性
  5. Qt+QGIS二次开发:开发环境搭建(超级详细)
  6. QT 读取txt文件的几种方法
  7. docker数据卷管理及网络基础配置
  8. 读《Top benefits of continuous integration》有感
  9. LeetCode263:Ugly Number
  10. [03] JSP指令