客户端代码:
var sendData = JSON.stringify({
name: document.forms["token"].name.value,
password:document.forms["token"].password.value
});
$.ajax({
url:'http://localhost:8088/log/',
type:'POST',
contentType:'application/json',
data: sendData,
dataType:"json"
})
node:
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.all("/log",function(req,res){
var name = req.body.name;
var password = req.body.password;
console.log(name,password)
...
}
发现name,password都是undefined,客户端传的json正常:
{"name":"fafa","password":"afa"}
请问这是怎么回事呢?谢谢