¿Hay alguna forma de actualizar DOM en ajaxComplete? Puedo obtener y modificar responseJSON, responseText, etc. pero no quiero meterme con el texto y buscar el elemento correcto.
$(document).ajaxComplete((event, xhr) => { let y = $('a')[0].getElementsByClassName('b')[0]; y.onclick = (event2) => { console.log(event2); return false; }; }Cuando estoy haciendo lo anterior, no está adjuntando el evento al nuevo elemento DOM recuperado, sino al anterior, supongo.
Quiero adjuntar el evento al nuevo elemento DOM recuperado.
EDITAR:
He intentado usar este objeto de evento y $ pero todas estas variables están relacionadas con el DOM 'antiguo'
Parece que estás usando jQuery. jQuery tiene un asistente ajax sofisticado.
$.ajax({ url : "/api/get/user" // User Ajax endpoint, method : "GET", // your Ajax method . post, get put data : // data you want to sent to the backend }).fail(function() { // If Ajax failed then do this }).done(function(data) { // If Ajax success then do this }); En el caso del usuario, lo que hago, llamaré a mis funciones (en su caso, tal vez ajaxComplete ) dentro de .done()
y voy a reemplazar
let y = $('a')[0].getElementsByClassName('b')[0];por
let y = $('a').find('b'); // or dynamic class or idlápiz de código: https://codepen.io/umanda/pen/abwboqp