0
I created a function for simple search, according to the code below
function pesquisar(){
var pesquisa = document.getElementById('pesquisa').value
window.location.pathname = 'produtos'
window.location.search = 'pesquisa=' + pesquisa
}
<div class="col-6 col-md-4 order-2 order-md-1 site-search-icon text-left">
<form action="javascript:pesquisar()" class="site-block-top-search">
<span class="icon icon-search2"></span>
<input type="text" class="form-control border-0" placeholder="Pesquisar" id="pesquisa">
</form>
</div>
This even works to change the search value, but the pathname value is not being changed
When the command is typed directly into the browser console, it is running perfectly
Would anyone know a possible reason?
@EDIT
If useful, below is the application backend
router.get('/produtos', function (req, res) {
if(req.query.pesquisa){
resultado = {nome: new RegExp(req.query.pesquisa, 'i')}
}else{
resultado = {}
}
_produto.paginate(resultado, { limit: 21, page: req.query.pag, sort: {nome: 'asc', cadastro: 'desc'} }, function (err, res) {
if (!res.page) {
res.page = 1
res.nextPage = 2
res.hasPrevPage = false
res.hasNextPage = true
}
return res
}).then(function (produto) {
res.render('produtos', { produto: produto.docs, pag: produto })
})
})
Hello Jose? Where is Noode.js there? What do you want to do exactly? Because a form changes the URL via action attribute; if you use get, your variable will already be passed. If you use ajax search, you need to prevent the browser from reloading with default Prevent and collecting the data, where changing URL is just one step to this. Finally, you know Jquery?
– Leonardo Negrão
Good morning, I’m still studying, I’ve done the application backend, but I don’t know good practices to perform some actions like research for example, and as I’m studying I prefer to create my own ways to do the actions, I can currently do the search by typing in the url, so I just need to change the url when the user type what they want in the input, I already edit the post and include the part of the backend
– José Augusto Megres
Remembering also, that the reason to put /products is only to redirect to the correct page at the time of the search, if the user is on another page in my application, I will keep trying, and send updates if I get something
– José Augusto Megres