title: CakePhp Ajax Autocomplete
body: <p>I am trying to get Ajax autocomplete setup for a textbox in CakePhp 2.x.</p>
  
  <p>In my view I have:</p>
  
  <pre><code>&lt;?php $this-&gt;start('script'); ?&gt;
  &lt;script type="text/javascript"&gt;
      $(document).ready(function () {
          var options, a;
          jQuery(function() {
              options = { 
                  serviceUrl: "&lt;?php echo $this-&gt;Html-&gt;Url(array('Controller' =&gt; 'Logs', 'action' =&gt; 'autoComplete')); ?&gt;",
                  minChars: 2,
              };
              a = $('#LogTimeSpent').autocomplete(options);
          });
      });
      $('#saveCust').click(function () {
          alert("Test")
      });
  &lt;/script&gt;
  &lt;?php $this-&gt;end(); ?&gt;
  </code></pre>
  
  <p>In my controller I have:</p>
  
  <pre><code>function autoComplete($query) {
      if ($this-&gt;request-&gt;is('ajax'))
      {
          $suggestions = $this-&gt;Customer-&gt;find('all', array(
              'conditions' =&gt; array(
                  'Customer.fullName LIKE' =&gt; '%'.$query.'%'
                  )
              ));
          return json_encode(array('query' =&gt; $query, 'suggestions' =&gt; $suggestions));
  
      }
  }
  </code></pre>
  
  <p>Customer.fullName is a virtual field if that affects the query.  Firebug is currently giving me a 500 internal server error.</p>