Answer the question
In order to leave comments, you need to log in
How to reload a file with JavaScript when re-AJAX-rendering the same view-file containing a link to this JavaScript-file?
I made a modal window, wrapped its contents in . Inside this block, I implemented navigation between three pages (view-files):
view1
view2
view3
Moving forward through the pages is done by clicking on elements (buttons or selecting an element from the list), in the opposite direction - using the elements at the top of the page. To move from one page to another, an ajax request is generated to a specific controller action, and renderAjax is returned, which replaces the data inside the block with a view file .
In the displayed views there are JavaScript scripts connected as directly:<div id='modalContent'>
<div id='modalContent'>
$script = <<< JS
$('.res').click(function(event) {
$.ajax({
type: "GET",
url: "load-resources?kind_of_res_id="+$(this).data("action"),
success: function(data) {
$("#modalContent").html(data)
}
})
});
JS;
$this->registerJs($script);
$this->registerJsFile(
'/basic_yii/web/scripts/resource/computer.js',
['depends'=>'app\assets\AppAsset']
);
<script>
Answer the question
In order to leave comments, you need to log in
Do not try to use your options for loading dynamic content in Yii2. There is pjax, which will take care of everything. Read and try to screw it for your purpose.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question