title: parse list on page getting by ajax
body: <p>I have dropdown country, State and city. I wrote controller and GET list of State by country Id witch I add like that</p>
  <pre><code>&lt;option value=&quot;1&quot;&gt; Afghanistan &lt;/option&gt;
  &lt;option value=&quot;2&quot;&gt; Aland Islands &lt;/option&gt;
  ...
  </code></pre>
  <p>Controller retrieve list of states I see it in browser console(Response)</p>
  <pre><code>[{id: 2954, name: &quot;Mogilev Region&quot;}, {id: 2955, name: &quot;Gomel Region&quot;},…]
  0: {id: 2954, name: &quot;Mogilev Region&quot;}
  1: {id: 2955, name: &quot;Gomel Region&quot;}
  2: {id: 2956, name: &quot;Grodno Region&quot;}
  3: {id: 2957, name: &quot;Minsk Region&quot;}
  4: {id: 2958, name: &quot;Minsk&quot;}
  5: {id: 2959, name: &quot;Brest Region&quot;}
  6: {id: 2960, name: &quot;Vitebsk Region&quot;}
  </code></pre>
  <p>My Controller:</p>
  <pre><code>@GetMapping(&quot;/country&quot;)
  public @ResponseBody List&lt;States&gt;  getStates(@RequestParam(&quot;countryId&quot;) Long countryId){
      List&lt;States&gt; stateList = countryRepo.findAllById(countryId);
      return stateList;
  }
  </code></pre>
  <p>Question is how parse information to select? I try some various code nothing work.</p>
  <pre><code>    $(&quot;#countryId&quot;).change(function () {
          var countryId = $(&quot;#countryId&quot;).val();
          $.ajax({
              type: 'GET',
              url: '/country?countryId='+countryId,
              dataType: 'html',
              success: function (states) {
                  var html = '';
                  var len = states.length;
                  for (var i = 0; i &lt; len; i++) {
                      html += '&lt;option value=&quot;' + states[i].id + '&quot;&gt;'
                          + states[i].name
                          + '&lt;/option&gt;';
                  }
                  $('#stateop').html(html);
  
              }
          });
      });
  </code></pre>
  <p>States show one long string like that: &quot;undefinedundefinedundefinedundefinedundefinedundefined&quot;.
  How parse response properly?</p>