title: How to make Ajax request to controller function in yii
body: <p>This is my js code:</p>
  
  <pre><code>var durl = "&lt;?php echo Yii::$app-&gt;getUrlManager()-&gt;getBaseUrl(); ?&gt;/Site/ReqAJAX";
  
  $.ajax({ 
      type: "POST", 
      url: durl,
      data: {_csrf:'&lt;?=\Yii::$app-&gt;request-&gt;csrfToken?&gt;'},
      dataType: "json",
      contentType: "application/json; charset=utf-8",
      success: function(msg) { 
          alert("Success "+msg); 
      },
      error: function(err) {   
          alert(JSON.stringify(err)); 
      } 
  });
  </code></pre>
  
  <p>This is the error i get:</p>
  
  <p><a href="https://i.stack.imgur.com/paVtS.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/paVtS.png" alt="enter image description here"></a></p>