title: Cross domain error on Ajax call, Yii2
body: <p>Here is simplified version of my probem.</p>
  
  <p>I try to make a simple ajax call on a view to specific controller/action url and expecting json response.</p>
  
  <p><strong>views/artwork/ajax.js</strong></p>
  
  <pre><code>ajaxRequest = $.ajax({
      type: "post",
      dataType: 'json',
      url: "/index.php?r=artwork/search",
      data: { "globalSearch": "somesearchterm" }
  });
  </code></pre>
  
  <p>An action that correspond to the request, in this case, <code>actionSearch</code>, just simply return back the parameter's value <code>globalSearch</code> as response. </p>
  
  <p><strong>Controllers/ArtworkController.php</strong></p>
  
  <pre><code>public function actionSearch()
  {
      if (Yii::$app-&gt;request-&gt;isAjax) {
  
          Yii::$app-&gt;response-&gt;format = Response::FORMAT_JSON;
  
          $sterm = Yii::$app-&gt;$request-&gt;post('globalSearch');
  
          $res = array(
              'logicresult' =&gt; $sterm,
              'success' =&gt; true,
          );
  
          return $res;
      }
  }
  </code></pre>
  
  <p>However, I got an jquery crossdomain error. what have i done wrong?</p>
  
  <p>Chrome Console Log</p>
  
  <pre><code>POST http://localhost/index.php?r=artwork%2Fsearch 500 (Internal Server Error)
  n.ajaxTransport.k.cors.a.crossDomain.send @ jquery.min.js:4
  n.extend.ajax @ jquery.min.js:4handleAjaxLink @ajax.js:19
  n.event.dispatch @ jquery.min.js:3
  n.event.add.r.handle @ jquery.min.js:3
  </code></pre>