-2
I have a code where the user inserts the student ID and so it is redirected to a page with only the student presences, but if the user does not enter any data in the input it displays all presences, what can I be doing to fix? BS: I’ve tried several ways but none worked, I think the logic is a little crooked, but I’m new and trying to go slowly and see what I can, I wanted to know what to do to make it work properly
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="card">
<div class="card-body">
<h3>Coloque a matricula de seu filho </h3>
<input type="text" name="nome" class="form-control" id="campoInput" placeholder="Digite o número da matricula">
<button type="submit" id="btnInput" class="btn btn-success mt-2" >Pesquisar</button>
</div>
</div>
<script>
$("#btnInput").on("click",function(e){
var urlFixa = "localhost:8081/exibir/";
var valorInput = $("#campoInput").val();
var urlFinal = urlFixa + valorInput + "";
$("#campoInput").attr("src",urlFinal);
$("#srcImg").html(urlFinal);
window.location.href = 'exibir/'+valorInput;
})
</script>
Edit 1:
Filter code that made with Node.js and sequelize:
app.get('/exibir/:id', function (req, res) {
Aluno.findAll({ order: [['idAluno', 'DESC']]}).then(function (alunos) {
const alunosdb = alunos
Post.findAll({
where:{ conteudo: {[Op.substring]: req.params.id }},
order: [['id', 'DESC']]}).then(function (posts) {
res.render('frequencia', { posts: posts, alunos: alunosdb })
})
})
})
I think the logic is quite wrong, I was able to understand the functioning of GET and POST, but I could not apply the get in this logic. I used Node.js and sequelize as a backend to make a data filter, where I basically took the value of the input and played in the url so the search page just took the req.params of the url and filtered according to the information of the url that came from the input. The application link: http://testepresenca-com-br.umbler.net/ I put the filter code on the Edit of the question
– André Cabral
In case I have no experience with javascript serverside, I tried to illustrate a solution with what I have in hand for backends.
– Ricardo Cenci Fabris