Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

170
Vistas
How to set two values to one html button

I'm working on a page where i'm rendering data from an api, where i make dynamic profile cards. And on clicking the button inside the card i'm calling an api through ajax. my problem is i need two values to pass to req.body to make the ajax success. I mananged the api call using one data using this code,

<div class="container" id="bb1">
        <% locals.posts.rows.forEach(function (patient) { %>
            
            <div class="patient-data">
              <div >
                <div style="padding-left: 100px"> <img src="<%= patient.dp %>" style="width: 45%;">  </div>
                <br>
              <div style="text-align: center;">
                <h5> P.ID : <%= patient.p_id %></h5>
                <p>  Name : <%= patient.patient_name %></p> 
              </div>
                <div style="padding-left: 110px;margin-bottom:20px ;"> 
                  <button type = "button" id="<%= patient.p_id %>" onclick="approve(this.id)" type="button" class="btn btn-info btn-sm" id="btn-success" style="background-color: #D1B147;"> View</button> </a></div>
              </div>
                </div>
        <% }); %>
      
    </div>

then inside my script;

<script type="text/javascript">
  function approve(id) {
      var p_id = id;
      console.log(p_id);
      var data = {};
      data.p_id = p_id;

      $.ajax({
            type: 'POST',
            data: JSON.stringify(data),
             contentType: 'application/json',
             dataType: 'json',
             url: "http://localhost:5000/mData",                      
             success: function(data) {
                 console.log(data);
                 localStorage.setItem('myData', JSON.stringify(data));
                window.location.href = 'mastersessionhistory';
                },
                
              error: function(){
                alert("Error")
                console.log('error occured')
              }
        })
   }    
 </script>

using this i was able to hit api and return values. i needed only the p_id to hit api. But now i have new key m_id to so my req.body should be {p_id,m_id}. How to include m_id on that bitton click so that i can call the api. can i use this

<button type = "button" id="<%= patient.p_id, patient.m_id%>" onclick="approve(this.id)" type="button" class="btn btn-info btn-sm" id="btn-success" style="background-color: #D1B147;"> View</button> </a></div>
about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda