Ajaxリクエストを表現に送信すると、req.body.emailを使用してjsonデータをキャッチします コンソールの出力は未定義です。...助けてください...
クライアント側
$.ajax({
url: "/getRandomPass",
dataType: "json",
data:{"emailId":"sampleemailiD@gmail.com"},
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);
});
回答:
回答№1は0Json strucutreを使用するには、$。getJSONを使用します。リンクを確認 http://api.jquery.com/jquery.getjson/
$.getJSON("/getRandomPass", function( data ) {
console.log("on success",data);
});
回答№2の場合は0
次のいずれかを使用する必要があります。
res.set("Content-Type", "text/plain");
res.send(text)
または:
res.end(text)