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

122
Views
Obtener un elemento con un ID generado dinámicamente

Tengo algo muy sencillo que estoy tratando de hacer, pero soy nuevo en Javascript.

Tengo una página HTML que genera una serie de elementos DIV con una ID que se genera dinámicamente.

Ejemplo: <div id="shots_234"></div> , <div id="shots_256"></div>

Estoy haciendo una solicitud jQuery AJAX y quiero completar el html con la respuesta dirigida a una de esas ID.

 function WeddingsShotDown(shotid, segmentid) { document.getElementById('ShotDownId').value = shotid; var form = document.getElementById('ShotDown'); var formData = new FormData(form); var id = "shots_" + segmentid; var divid = document.getElementById(id); console.log("Div: " + divid); $.ajax({ url: '/Weddings/ShotDown', type: 'POST', data: formData, dataType: 'html', processData: false, contentType: false, success: function (response) { if (response) { $("#shots_" + segmentid).html(response); document.getElementById('ShotId').value = ""; showNotification("success", "Your shot sequence has been updated", "far fa-check-circle"); } else { showNotification("danger", "Error saving shot sequence", "far fa-check-circle"); } } }); }

entonces tampoco

 $("#shots_" + segmentid).html(response);

Ni

 var id = "shots_" + segmentid; var divid = document.getElementById(id);

Consígueme el div que quiero.

¿Cómo puedo actualizar ese elemento?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

  • Var segmentid no existe en la función de éxito. Intente, guarde la identificación en la solicitud con beforeSend y obtenga la recepción:
 $.ajax({ url: '/Weddings/ShotDown', type: 'POST', data: formData, dataType: 'html', processData: false, contentType: false, beforeSend:function( jqXHR ){ jqXHR.id = segmentid; } }).done(function(response, msgStatus, jqXHR){ if (response) { $("#shots_" + jqXHR.id).html(response); document.getElementById('ShotId').value = ""; showNotification("success", "Your shot sequence has been updated", "far fa-check-circle"); } else { showNotification("danger", "Error saving shot sequence", "far fa-check-circle"); } });
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!