login.ejs has following code
<input type="text" name="addUser_license" id="addUser_license" />
<!-- Display the search results -->
<ul>
<% license_users.forEach((user2) => { %>
<li><script> console.log("<%- user2.license_key %>");</script></li>
<% }) %>
</ul>
and my ajax code is
$("#addUser_license").blur(function () {
let myTxt = $(this).val();
var formData = {
"license_key": myTxt,
};
$.ajax({
type: "POST",
dataType: "JSON",
url: "/license",
data: formData,
})
.done(function (response) {
console.log("Success: " + response.msg);
console.log(data);
})
.fail(function (response) {
console.log("Error: " + response.msg);
console.log(myTxt);
console.log(formData);
});
});
and my post request of server side is
fastify.post("/license", async (request, reply) => {
const client = await fastify.pg.connect();
const { license_key } = request.body;
try {
const result = await client.query(
'SELECT * FROM license WHERE license_key LIKE $1',
[license_key]
);
// Pass the search results to the EJS template
reply.view( "/login.ejs", { license_users: result.rows } );
console.log(result.rows)
console.log(license_key)
} catch (err) {
console.error(err);
return reply.view("error.ejs");
} finally {
client.release();
}
});
following error occcur:
Error: undefined
and this line not works. Didn't any request to return
<li><script> console.log("<%- user2.license_key %>");</script></li>
and following console results fine show
console.log(result.rows) console.log(license_key)
i think this line not works properly
reply.view( "/login.ejs", { license_users: result.rows } );
But i don't know why this not working? what should i do?