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

182
Views
Same AJAX call for multiple button on clicks on the same page

I'm working on a project with Django. I have multiple buttons on a page. When clicking one of these buttons I want to get the value of it without the page refreshing.

With the below code it does want I want except that it will only return the value of the first button on the page regardless of which button I click.

Please note that I have zero experience with JS which is why I'm struggling. I've looked at many, many threads and I can't figure it out.

<article class="media content-section">
  <div class="media-body">
    <div class="article-metadata">
      <h2>{{ ingredient.group }}</h2>
    </div>
    <button id="{{ ingredient.pk }}" class="testing" value="{{ ingredient.food_name }}">{{ ingredient.food_name }}</button>
  </div>
</article>
$(document).on('click', '.testing', function(e) {
  e.preventDefault();

  $.ajax({
    type: 'POST',
    url: '{% url "select" %}',
    data: {
      value: $('.testing').val(),
      csrfmiddlewaretoken: $('input[name=csrfmiddlewaretoken]').val(),
      // action: 'post',
      success: function(json) {
        console.log("success"); // another sanity check
        console.log($('.testing').val())
      },
    }
  })
})
about 4 years ago · Juan Pablo Isaza
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!