ajax提交request.body无法拿到参数
ajax提交的问题困惑我已晚上,各种方法都试了可就死拿不到参数值,用的是express4.x,代码如下
<div class="form-group">
<label for="exampleInputEmail1">邮箱</label>
<input type="email" class="form-control" id="exampleInputEmail1" name="email" placeholder="Email">
</div>
<div class="form-group">
<label for="exampleInputPassword1">密码</label>
<input type="password" class="form-control" id="exampleInputPassword1" name="pwd" placeholder="Password">
</div>
<script>
jQuery(document).ready(function() {
$("#form_submit").bind("click",function(){
var email = $("#exampleInputEmail1").val();
var pwd = $("#exampleInputPassword1").val();
console.log(email);
$.ajax({
url:'/loginverificat',
type:'post',
contentType:"application/json",
data: JSON.stringify({email:email,pwd:pwd}),
success: function(data){
console.log(data);
},
error: function(data,status){
console.log("error");
}
});
});
});
后台
var express = require("express");
var app = express();
app.use(express.static(__dirname +"/public"));
app.post("/loginverificat",function(req,res){
console.log(JSON.stringify(req.body.email));
// console.log(JSON.stringify(req.ip));
console.log(JSON.stringify(req.params));
console.log(JSON.stringify(req.query));
});
app.get("/login",function(req,res){
res.sendFile(ablotePath+"login.html");
});
app.listen(8888);
console.log("lissten port 8888")
刚开始接触node.js,希望有这方面的经验朋友帮忙解释下这个问题