當我發送Ajax請求來表示我使用req.body.email來捕獲json數據 控制檯中的輸出給我undefined ....請幫助...jquery ajax到Express無法捕獲數據json數據
客戶端
$.ajax({
url: '/getRandomPass',
dataType: "json",
data:{'emailId':'[email protected]'},
type: 'POST',
cache: false,
success: function(data) {
console.log("cleint recieved data",data);
// this.setState({data: data});
}.bind(this),
error: function(xhr, status, err) {
console.log(xhr,status,err);
}.bind(this)
})
服務器端
app.use(bodyParser.json());
app.post('/getRandomPass', function(req, res) {
console.log("req",req.body.emailId);
});
你設定的響應內容類型? – nikjohn
你的意思是'console.log(「成功」,數據);'輸出html內容? –
是成功的...... – shank