title: Send data in Ajax response
body: <p>hey I am trying to populate one select dropdown on the basis of another one using ajax. I have one select populated with portfolios and the 2nd one is empty. when I select an option from the 1st select box. I call an ajax function in which I send the selected portfolio id, In the ajax method I find the groups for the selected id, how can I populate the 2nd select with the groups I found. My code is </p>
  
  <p>The form which contains two selects</p>
  
  <pre><code>&lt;form name="portfolios" action="{{ path('v2_pm_portfolio_switch') }}" method="post" &gt;
          &lt;select id="portfolios" name="portfolio" style="width: 200px; height:25px;"&gt;
              &lt;option selected="selected" value="default"&gt;Select Portfolio&lt;/option&gt;
              {% for portfolio in portfolios %}
                  &lt;option get-groups="{{ path('v2_pm_patents_getgroups') }}" value={{ portfolio.id }}&gt;{{ portfolio.portfolioName }}&lt;/option&gt;
              {% endfor %}
          &lt;/select&gt;&lt;br/&gt;&lt;br/&gt;
          &lt;select id="portfolio-groups" name="portfolio-groups" style="width: 200px; height:25px;"&gt;
              &lt;option selected="selected" value="default"&gt;Select Portfolio Group&lt;/option&gt;
          &lt;/select&gt;&lt;br/&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>The JS </p>
  
  <pre><code> &lt;script&gt;
      $(document).ready(function(){
          $('#portfolios').change(function() {
              var id = $("#portfolios").val();
              var url = $('option:selected', this).attr("get-groups");
              var data = {PID:id};
              $.ajax({
                  type: "POST",
                  data: data,
                  url:url,
                  cache: false,
                  success: function(data) {
                      //want to populate the 2nd select box here
                  }
              });
          });
      }); 
  &lt;/script&gt;
  </code></pre>
  
  <p>Controller method where I find the groups for the selected portfolio</p>
  
  <pre><code>public function getgroupsAction(Request $request){
      if ($request-&gt;isXmlHttpRequest()) {
  
          $id = $request-&gt;get("PID");
          $em = $this-&gt;getDoctrine()-&gt;getEntityManager();
          $portfolio_groups = $em-&gt;getRepository('MunichInnovationGroupPatentBundle:PmPatentgroups')
          -&gt;getpatentgroups($id);
          return $portfolio_groups;
      }
  }
  </code></pre>
  
  <p>Any idea how can i send the portfolio groups and populate the 2nd select</p>
  
  <p>thanks in advance</p>