Saturday, November 28, 2009

$ajax->autocomplete empty results

So I've been pulling my hair out over this and I'm hoping somebody can
lend some advice. I have a very basic auto-complete that I cannot get
to work correctly.

The problem I'm having is that I cannot get any results listed in the
div of my auto-complete, its always blank when I try to pull data from
another Model/Controller. If I provide a static HTML file as the data
(url) for the auto-complete field it works fine.

I've checked, double checked and triple checked that my controller is
properly outputting the data for the auto-complete function, and it
spits out a nicely formatted unordered list:

<ul>
<li id="11">Chicken Brests</li>
<li id="21">Cinnamon Sticks</li>
<li id="46">Coffee Stirrers</li>
<li id="10">Corn Starch</li>
</ul>

And like I said, if I put the exact same HTML in a static page and
reference it in my $ajax->autocomplete() call it will display just
fine.

I've also watched the query's happening with Firebug so I know the URL
is getting called correctly, and the POST content is getting sent
properly.

I'm truly at a loss as to what else to look at and I'm hoping somebody
can point me in the right directly or see something I missed.

----- Input Form -----

<?php echo $form->create('Shoppinglist'); ?>
<?php echo $ajax->autocomplete('Item.title', '/items/query'); ?>
<?php echo $button->submit('Add Item','icons/
add.png','positive',true); ?>
<?php echo $form->end(); ?>

----- Item list function -----

function query($q = null) {
// Debugging line, if not called with POST, shortcut a search for
'c'
if(empty($this->data)) $this->data['Item']['title'] = 'c';

$this->set('items', $this->Item->find('all', array(
'conditions' => array(
'Item.title LIKE' => '%'.$this->data['Item']['title'].'%'
),
'order' => array('Item.title' => 'ASC'),
'fields' => array('id','title')
)));
$this->layout = 'ajax';
}

Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions.

You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en

No comments: