Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

189
Views
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>
`           `
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

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?

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!