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

130
Views
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 answers
Answer question

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 Report

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 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!