S
S
Sonnabend2015-04-09 20:17:19
JavaScript
Sonnabend, 2015-04-09 20:17:19

How to call actions in a specific controller using Javascript in Yii2?

The problem is this: the site menu is drawn using SVG code due to the complexity of the presentation. How can I run actions? Let's say I want to run site/login from the demo. OUTSIDE an svg block, the following command works:
<?= Html::a(Yii::t('app', '0'), ['site/login']) ?>
But inside an svg block, it doesn't work:

<svg>
...
<text id="s3" transform="matrix(1 0 0 1 80.3013 72.0967)" fill="#D4EBFF" font-family="'ArialMT'"
                  font-size="29" style="cursor: pointer;"><?= Html::a(Yii::t('app', '0'), ['site/login']) ?>
            </text>
...
</svg>

I think you can do it using Ajax request, but none of the following options work:
$('#s3').click(function(){
    $.post('/yii2/controllers/SiteController.php', {r:'site/login'});
});

$('#s3').click(function(){
    $.post('?r=site/login');
});

I apologize in advance if I wrote some stupidity, since I just recently had to work with SVG and PHP. Before that, the experience was only in JS. But I think the problem is clearly enough described.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
vyachin, 2015-04-13
@sonnabend

$('#s3').click(function () {
    location.href = '<?=Url::to(['site/login']) ?>';
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question