title: Ajax call populate Typeahead Bootstrap
body: <p>What I'm trying to do is to get a json object via Ajax and populate the Bootstrap Typeahead with just one kind of value.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>nameTypeHead: function () {
          var _self = this,
              searchInput = $('#nameTypeHead'),
              arr = [];
  
          function getArray() {
              $.ajax({
                  url: '/Home/AutoComplete',
                  type: 'post',
                  dataType: 'json',
                  data: { searchText: searchInput.val() },
                  success: function (data) {
                      $.each(data, function () {
                          arr.push(this.Name);
                      });
                      return arr;
                  }
              });
          }
  
          searchInput.typeahead({
              source: getArray()
          });
      } 
  </code></pre>
  
  <p>I receive the error that <strong>arr is null</strong></p>
  
  <p>I also tried with <code>.parseJSON()</code> but with no success:</p>
  
  <pre><code>$.each($.parseJSON(data), function () {
     arr.push(this.Name);
  });
  </code></pre>
  
  <p>What can I do to show just the value Name of my Json Object in the Typeahed?</p>
  
  <p>If in the Ajax Success I put <code>alert(JSON.stringify(data));</code> it alert correctly my Json Object.</p>