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?
$.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"); } });