I can't get data from the method getuserpost. The web page stucks and doesn't show anything.
The rest of the code works well adding and deleting data and then redirecting to the home page but that method does not show the JSON output. I have tried with res.send and res.render but nothing.
Does someone know what's wrong with this code?
app.get('/getuser', (req, res) => {
res.render('getuser');
});
//DOESN'T WORK
app.post('/getuserpost', (req, res) => {
const query = datastore.createQuery('usersTable').filter('girl', req.body.girl_field).order('timestamp', { descending: true }).limit(10);
datastore.runQuery(query).then((results) => {
const entities = results[0];
res.json(entities[0]);
});
});
This is the HTML for that method:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<form action="/getuserpost/" method="POST">
<label for="girl_name">Enter girl: </label>
<input id="girl_name" type="text" name="girl_field" value="Default girl for user">
<input type="submit" value="OK">
</form>
<br>
<a href="/home">Home</a>
<br>
<a href="/adduser">Add user</a>
<br>
<a href="/updateuser">Update user</a>
<br>
<a href="/deleteuser">Delete user</a>
<br>
</body>
</html>
I'm using Google Datastore with Google App Engine.