I have the following code. The Get request gets checked as correct, but Post returns “First is undefined”. It seems the get request did not grab the value of req.query.first. Why?
From the home page, both first name and last names fields in the form are filled, then I click Submit button.
app.get("/name", function(req, res){
console.log(“GET, Query is " + req.query);
var firstname = req.query.first;
var lastname = req.query.last;
res.json({name: ${firstname} ${lastname}
});
})
app.post(”/name", function(req, res){
var string = req.body.first + " " + req.body.last;
res.json({name: string});
})
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.90 Safari/537.36
.
Challenge: Get Data from POST Requests
Link to the challenge: