Yii2 + ajax not working
<p>I tried use answers about yii and ajax but not finded working examle.
My script in yii2 bacis views/site/about.php:</p>

<pre><code>&lt;script&gt;
    function myFunction()
    {
        $.ajax({
            url: '&lt;?php echo Yii::$app-&gt;request-&gt;baseUrl . '/controllers/SiteController/sample' ?&gt;',
            type: 'post',
            data: {
                searchname: 10,
                searchby: 25,
                _csrf: '&lt;?= Yii::$app-&gt;request-&gt;getCsrfToken() ?&gt;'
            },
            success: function (data) {
                console.log(data.search);
                console.log(data.code);
            }
        });

    }
&lt;/script&gt;
</code></pre>

<p>My function in SiteController:</p>

<pre><code>   public function actionSample() {

        if (Yii::$app-&gt;request-&gt;isAjax) {

            $search = "some-string";
            $code = 20;
            \Yii::$app-&gt;response-&gt;format = \yii\web\Response::FORMAT_JSON;
            return [
                'search' =&gt; $search,
                'code' =&gt; $code,
            ];
        }
    }
</code></pre>

<p>I see post  from ajax in browser OK.</p>

<pre><code> POST http://localhost/web/controllers/SiteController/sample    
    200 OK
</code></pre>

<p>But conroller not answer . I get: "undefined".
May be problems with url? But I tried other:
<code>Yii::$app-&gt;request-&gt;baseUrl . '/controllers/sample</code>. It didnt work too(</p>