title: Bootstrap Typeahead w Laravel Uncaught TypeError: Cannot read property 'length' of undefined
body: <p>I am trying to use autocomplete in  tags field of my form using Bootstrap Typeahead. When I type a letter now I have an error telling me in chrome developer tools : </p>
  
  <pre><code>Uncaught TypeError: Cannot read property 'length' of undefined 
  </code></pre>
  
  <p>My form is shortly :</p>
  
  <pre><code>    &lt;form class="form-horizontal" method="post" action="" autocomplete="off"&gt;
          &lt;!-- CSRF Token --&gt;
       .....
       &lt;!-- Tags --&gt;
        &lt;div class="control-group {{ $errors-&gt;has('tag_id') ? 'error' : '' }}"&gt;
          &lt;label class="control-label" for="tags"&gt;Tags&lt;/label&gt;
             &lt;div class="controls"&gt;
               &lt;input type="text" class="typeahead" data-provide="typeahead"   autocomplete="off" &gt;
               {{ $errors-&gt;first('tag_id', '&lt;span class="help-inline"&gt;:message&lt;/span&gt;') }}
             &lt;/div&gt;
        &lt;/div&gt;
        .....
      &lt;/form&gt;
  </code></pre>
  
  <p>I use admin prefix with my blogs : </p>
  
  <pre><code>Route::group(array('prefix' =&gt; 'admin'), function()
  {
    Route::get('/', array('as' =&gt; 'blogs', 'uses' =&gt; 'Controllers\Admin\BlogsController@getIndex'));
          Route::get('create', array('as' =&gt; 'create/blog', 'uses' =&gt; 'Controllers\Admin\BlogsController@getCreate'));
          Route::post('create', 'Controllers\Admin\BlogsController@postCreate');
          Route::post('tags', 'Controllers\Admin\BlogsController@postTags');
  }
  </code></pre>
  
  <p>my controller is :</p>
  
  <pre><code>public function postTags()
  {
        $query = Input::get('query');
  
        $results = Tag::select( 'name' )-&gt;where( 'name', 'LIKE', '%' . $query . '%')-&gt;get();
  
        $data = array();
        // Loop through the results.
        //
        foreach ( $results as $result ):
                 $data[] = $result-&gt;name;
        endforeach;
  
              // Return a response.
              //
       return Response::json($data);
  
  }
  </code></pre>
  
  <p>And I tried to activate typeahead</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
       $('.typeahead').typeahead({
                    source : function(typeahead, query){
                  $.ajax({
                      url      : 'tags',
                      type     : 'POST',
                      data     : { query : query, column : 'name' },
                      dataType : 'json',
                      async    : true,
                      success  : function(data) {
                          return process(data.titles);
                      }
                  });
              }
      });
  &lt;/script&gt;
  </code></pre>
  
  <p>How can I fix this error ? </p>
  
  <p>Thank you.</p>