usa mi funcion en reporte, haz reporte flexible de errores (si no encuentra botones hace…
- User
usa mi funcion en reporte, haz reporte flexible de errores (si no encuentra botones hace return)
async function enviarAjax(action, data = {}) { try { const body = new URLSearchParams({ action: action, ...data });
codelogAjax('Cuerpo de la solicitud que se enviará:', body.toString()); const response = await fetch(ajaxUrl, { method: 'POST', headers: { 'Content-Type': 'application/x-www-form-urlencoded' }, body: body }); if (!response.ok) { throw new Error(`HTTP error! status: ${response.status}`); } let responseData; const responseText = await response.text(); try { responseData = JSON.parse(responseText); } catch (jsonError) { console.warn('No se pudo interpretar la respuesta como JSON:', jsonError); responseData = responseText; } logAjax('Respuesta del servidor:', responseData); return responseData; } catch (error) { console.error('Error en la solicitud:', error); return { success: false, message: error.message }; }}
function reporte() { // Capturamos todos los botones reportar document.querySelectorAll('.reporte').forEach(function(button) { button.addEventListener('click', function() { const postId = this.getAttribute('data-post-id'); const tipoContenido = 'post'; // Puedes cambiar esto según el tipo de contenido abrirModal(postId, tipoContenido); }); });
code - Assistant