I'm having Javascript problem. Created Javascript modal function, which use AJAX to get its content, and innerHTML function puts content into modal. Modal shows content with no problem, but Javascript do not work inside of it. When I inspect element it shows ... with all functions I need, but that doesn't work. I use twig template machine for rendering page and modal, so maybe it could cause that problem?
// index.php where modal shows up
echo $twig->render(...);
// Modal function
function openModal() {
const request = new XMLHttpRequest();
request.open('post', 'modalfile.php');
request.onload = function () {
document.querySelector('.modal-content').innerHTML = request.response;
}
request.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
request.send();
document.querySelector('.overflow').style.visibility = 'visible';
document.querySelector('.modal').style.visibility = 'visible';
}
// modalfile.php
echo $twig->render(...);
If I am right and Javascript problem causes Twig - is it possible to solve that problem? Or maybe it is any other problem?