title: Callback of Ajax request using Jquery
body: <p>Edited JS file :<br>
  <br>Style 1:<br></p>
  
  <pre><code>$(document).ready(function() {&lt;br&gt;
  $("#rootFolder").change(function(){&lt;br&gt;
  var rootFolderValue = $('#rootFolder').val();&lt;br&gt;
  //alert (rootFolderValue);&lt;br&gt;
  $.getJSON("getSubfolder.jsp", { foldername: rootFolderValue }, function(json) {&lt;br&gt;
  
  $.each(json, function(i, option) {&lt;br&gt;
  
  $('#subFolder1').append($('').val(option.Value).html(option.Text));&lt;br&gt;
  });&lt;br&gt;
  });&lt;br&gt;
  });&lt;br&gt;
  
  });&lt;br&gt;
  &lt;br&gt;
  </code></pre>
  
  <p>Style 2<br><br></p>
  
  <pre><code>$(document).ready(function() {&lt;br&gt;
  $("#rootFolder").change(function(){&lt;br&gt;
  var rootFolderValue = $('#rootFolder').val();&lt;br&gt;
  alert (rootFolderValue);&lt;br&gt;
  $.ajax({&lt;br&gt;
  &lt;br&gt;
  url: 'sample.jsp',&lt;br&gt;
  data:'foldername='+rootFolderValue,&lt;br&gt;
  dataType: "json",&lt;br&gt;
  success:function(data){&lt;br&gt;
      $.each(data , function (key , value) {&lt;br&gt;
          $('#subFolder').append('&lt;option value="'+key+'"&gt;"'+value+'"&lt;/option&gt;');&lt;br&gt;
       });&lt;br&gt;
  }&lt;br&gt;
  });&lt;br&gt;
  });&lt;br&gt;
  });&lt;br&gt;
  </code></pre>
  
  <p>getSubfolder.jsp file<br>
  <br></p>
  
  <pre><code>&lt;%&lt;br&gt;
      String root = request.getParameter("foldername");&lt;br&gt;
      System.out.println("the value is "+root);&lt;br&gt;
      JSONObject arrayObj=new JSONObject();&lt;br&gt;
      String path = "G:\\Demo\\"+root;&lt;br&gt;
      File rootFile = new File(path);&lt;br&gt;
      File[] listOfDirs = rootFile.listFiles();&lt;br&gt;
       for (int i = 0; i &lt; listOfDirs.length; i++)&lt;br&gt;
      {        &lt;br&gt;
      if (listOfDirs[i].isDirectory())&lt;br&gt;
      {&lt;br&gt;
         arrayObj.put(i,listOfDirs[i].getName().toString());&lt;br&gt;
  
      }&lt;br&gt;
      }&lt;br&gt;
      out.println(arrayObj);&lt;br&gt;
  %&gt;&lt;br&gt;
  </code></pre>
  
  <p>Problem:<br>
  1) My arrayObj has values {"0":"A","1":"B"}  . But the dropdown is still not changing. Please help.. i have tried both methods mentioned below to change the dropdown.. Just stuck with it all day :)</p>