A
A
Art4es2017-09-14 09:10:54
JavaScript
Art4es, 2017-09-14 09:10:54

How to load another view with js with code inside using Ajax in Yii2?

The current view has a modal window.
When the window pops up, it is loaded using xmlhttprequest with the result of rendering the view, which has html markup and the js code applicable to it.
An example of the content of the view (which is being loaded):

<div>
...
</div>

<?php 
$this->registerJs('console.log("smth")');
?>

This js code does not work when opening a modal window, but html is displayed correctly.
How can this problem be solved?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Art4es, 2017-09-14
@Art4es

The problem was that I was using innerHtml. When I used $.append() everything worked

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question