title: want to select user from onchange of dropdown list of department in cakephp?
body: <p>i have two tables user and department where department has two fields id and name i want to create a view so that when someone selects a department name from the dropdownlist the user's name of all in that department show in another dropdownlist using AJAX and How to call that in controller</p>
  
  <pre><code> &lt;script&gt;
  jQuery(document).ready(function ($) {
      //jQuery('#searchTable').dataTable();
      $('#department_id').change(function () {
          jQuery('#user').empty();
          var data2 = {};
          data2['department_id'] = jQuery(this).val();
          var json = JSON.stringify(data2);
          jQuery.ajax({
              type: "POST",
              url: "/AjaxRequests/name",
              data: json,
              dataType: "json",
              success: function (response) {
                  var app = "&lt;option value&gt;All&lt;/option&gt;";
                  jQuery('#user').append(app);
  
                  jQuery.each(response, function (i, text) {
                      jQuery('#user').append(jQuery('&lt;option&gt;&lt;/option&gt;').val(i).html(text));
                  });
  
              }
          });
      });
     &lt;/script&gt;
  </code></pre>
  
  <p>this is the script i am using 
  and in view the department dropdown is like this</p>
  
  <pre><code>     &lt;?php echo $this-&gt;Form-&gt;input('department_id', array('onChange' =&gt; 'showFields(this.value)', 'class' =&gt; 'form-control-custom', 'id' =&gt; 'department_id', 'type' =&gt; 'select', 'label' =&gt; true, 'label' =&gt; 'department:', 'options' =&gt; $departments, 'empty' =&gt; 'Select A Department', 'required' =&gt; 'false'))
      ?&gt;
  </code></pre>
  
  <p>Anyone please help me with this ajax and also the controller </p>