Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

297
Visualizações
How do I create a Django / Ajax redirect POST request on click?

I have a search function in my django app using ajax. It displays all results from a model.

I want to limit the number of results the search returns on the page though, so when the queryset is so large the user should click on a 'see all results', rather than having heaps of results in the search box.

I'm trying to do this by adding a HTML form below, but when I click on the href it is creating a GET request. I'm not totally sure what I need to fix up here to pass the data to the view and render the new page.

resultsBox.innerHTML += `
    <a href="${url} ${'results'}" class="item">
        <form method="POST" class="post-form" input type="submit"
            {% csrf_token %}
            <action="${url} ${'results'}">
        </form>
        <div class="row mt-2 mb-2">
            <div class="col-2">
                img placeholder
            </div>
            <div class="col-10">
                <h5>See all results for "${quote}"</h5>
            </div>
        </div>
    </a>
`           `
over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

You are wrapping the entire form in the href, you probably just want See all results to be the link?

resultsBox.innerHTML += `
    
        <form method="POST" class="post-form" input type="submit"
            {% csrf_token %}
            <action="${url} ${'results'}">
        </form>
        <div class="row mt-2 mb-2">
            <div class="col-2">
                img placeholder
            </div>
            <div class="col-10">
                 <h5>
                   <a href="${url} ${'results'}" class="item">
                      See all results for "${quote}"
                   </a>
                 </h5>
            </div>
        </div>`

Alternatively (as noted in the comments below): to avoid a GET and have a POST instead, you want to submit a form, not follow a hyperlink: How to submit a form with JavaScript by clicking a link?

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda