title: Yii2 Ajax .post to controller from dropdownList of view and some action upon receiving data
body: <p>I have a DropDown list. I've written the code but it's not working. Please help me to fix it:</p>
  
  <pre><code>echo $form-&gt;field($model, 'Adrop')-&gt;dropDownList(
      [
          '' =&gt; 'Please Choose',
          '1' =&gt; 'item 1',
          '2' =&gt; 'item 2'
      ],
      [
          'onchange' =&gt; '$.post(Yii::$app-&gt;urlManager-&gt;createUrl . "users/A_action"), function(data) {
              $("#test_div").html(data)
          }'
      ]
  );
  </code></pre>
  
  <p>Also I want to send selected data, and don't know where to write it.</p>
  
  <p>In the Controller I have this action</p>
  
  <pre><code> public function actionA_action() {
       $data = "TTT";
       return $data;
   }
  </code></pre>
  
  <p>Now when I select something in the DropDown list, nothing happens in my <code>test_div</code> :(</p>
  
  <p><strong>UPDATE</strong> 
  Thanks to Mihai P. now I'm using this code</p>
  
  <pre><code>&lt;?php
        echo   $form-&gt;field($model, 'Adrop')-&gt;dropDownList(
            [''=&gt;'Please Choose','1'=&gt;'item 1','2'=&gt;'item 2'],
            [
            'onchange'=&gt;'$.post( "'.Yii::$app-&gt;urlManager-&gt;createUrl(["users/A_action"]).'",function(data){
                  $("#test_div").html( data )
                  }']);
          ?&gt;
  </code></pre>
  
  <p>The HTML is formed in the following way</p>
  
  <pre><code>&lt;select id="A-adrop" class="form-control" name="A[Adrop]" onchange="$.post( &amp;quot;/users/A_action&amp;quot;,function(){
                  $(&amp;quot;#test_div&amp;quot;).html( data )
                  }"&gt;
  &lt;option value=""&gt;Please Choose&lt;/option&gt;
  &lt;option value="1"&gt;item 1&lt;/option&gt;
  &lt;option value="2"&gt;item 2&lt;/option&gt;
  &lt;/select&gt;
  </code></pre>
  
  <p>But when I choose something
  in debug this string is highlighted </p>
  
  <pre><code> &lt;option value="2"&gt;item 2&lt;/option&gt;
  </code></pre>
  
  <p>and there is one error saying</p>
  
  <pre><code>Uncaught SyntaxError: Unexpected token }
  </code></pre>
  
  <p><strong>Final UPDATE</strong></p>
  
  <p>I've added one closing bracket on the last string of this code there are two of them closing now as you can see, and that was the problem. Semicolumn also will be a plus, but I've tested code works without it OK. problem was in closing bracket.</p>
  
  <pre><code> 'onchange'=&gt;'$.post( "'.Yii::$app-&gt;urlManager-&gt;createUrl(["users/A_action"]).'",function(data){
                      $("#test_div").html( data );
                      })']);
  </code></pre>