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

131
Vistas
how can without refreshing pull data with ajax in django

I can post with ajax, but when I want to pull data without refreshing the page, I can only do it 2 times, then the button loses its function.

 <div>
                          <input type="hidden" name="producecode" class="pcode" value="{{per.produceCode}}" />
                          <input type="hidden" name="useremail" class="uponequantity" value="{{user.username}}" />
                          <button class="btn btn-sm btn-primary upoq"><i class="fa fa-plus"></i></button></div>

and jquery

 $.ajax({
    type: "POST",
    url: "/uponequantity/",
    headers: { "X-CSRFToken": '{{csrf_token}}' },
    data: {
    "producecode":$(this).parent().find(".pcode").val(),
    "useremail":$(".uponequantity").val(),
  },
    success: function() {
      window.location.assign('/basket/'+"?b="+$(".uponequantity").val());
    }

    
});
/*$.ajax({
              url:'/baskett/'+"?b="+$(".uponequantity").val(),
              headers: { "X-CSRFToken": '{{csrf_token}}' },
              type:'POST',
              success:function(result){
                  $('.basket').html(result);
      }
      });

*/

})
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

Just add another line to reference your second input same as the first.

$(".up").click(function(){
  $(".prdtd").find("input:first-  child").attr("value"); 
  $(".pcode").val()
  $(".uponequantity").val()//<-- new line for the second hidden value
}

-----------------------------------------
Update:
-----------------------------------------

OP has multiple buttons with the same class each in it's own div and wants to access the values within each div.

So, first off you need to change "pcode" from an id to class in order to get all instances. (id is for unique instances)

After that you need to be able to get the "pcode" & "uponequantity" that are associated with that button and one way of doing that is:

$(".up").click(function(){
  $(this).parent().find(".pcode").val()
  $(this).parent().find(".uponequantity").val()
}

Simply put, the this keyword references the clicked button.
You then get the direct parent element which would have the button and the hidden values as children.
Finally you get each specific child through the find command and do whatever you want with them.

about 4 years ago · Juan Pablo Isaza Denunciar

0

If I understand your question correctly, you would like to get the value of both inputs in your callback.

It seems like you misspelt pdcode in your JavaScript.

Does the below code snippet help?

$(".up").click(function() {
  const value1 = $(".pdcode").val();
  const value2 = $(".uponequantity").val();
}
about 4 years ago · Juan Pablo Isaza Denunciar
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