M
M
Messi2017-05-11 22:26:09
Yii
Messi, 2017-05-11 22:26:09

How to get the actual value of a variable?

The model has a $myVar variable. When a get request is received before a response is received, it is incremented, then passed to the controller and to views.
Added a form with Pjax

<?php Pjax::begin(); ?>
            <?= Html::beginForm('statistics', 'get', ['data-pjax' => '']) ?>
            <?= Html::input('text', 'ownerId') ?>
            <?= Html::submitButton('Отправить', ['class' => 'flat_button secondary']) ?>
            <?= Html::endForm() ?>
            <?= $myVar ?>
        <?php Pjax::end(); ?>

Added show loader while Pjax request is in progress.
js file:
$(document).ready(function() {
    $('.loader').hide()

    $(document).on('pjax:send', function() {
        $('.loader').show()
    })

    $(document).on('pjax:success', function() {
        $('.loader').hide()
    })
});

The question is how to pass the current value of the myVar variable to the View while the ajax get request is in progress?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
Boris Korobkov, 2017-05-12
@BorisKorobkov

How to pass PHP variable to JS variable?

<script>
var myJsVar = <?= $myPhpVar ?>;
</script>

How to pass PHP variable directly to ajax request?
<?= Html::input('hidden', $myPhpVar) ?>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question