CJuiAutoComplete Not Completing With Ajax

Hi,

I’ve been struggling with it for a few days so any help would be more than welcomed.

The problem : The plugin will autocomplete the text input if I provide a static array of string. It will get an answer back from my ajax call when using remote source but won’t use the data to generate the autocomplete list.

The code so far :

An extension called AutoCompletionAction :


<?php

	class AutoCompleteAction extends CAction

	{

		public $model;

		public $attribute;

		public $fields;

		private $results = array();


		public function run()

		{

			if(isset($this->model) && isset($this->attribute))

			{

				if(!isset($this->fields))

					$this->fields = array($this->attribute);


				$criteria = new CDbCriteria();

				$criteria->compare($this->attribute, $_GET['term'], true);

				$model = new $this->model;

				$row = array();

				

				foreach($model->findAll($criteria) as $m)

				{

					foreach($this->fields as $field)

						$row[$field] = $m->{$field};


					$this->results[] = $row;

				}


			}


			echo CJSON::encode($this->results);

		}

	}

?>

It is added to a Controller this way :


public function actions() {

	return array(

		'aclist'=>array(

			'class'=>'application.extensions.AutoCompleteAction',

			'model'=>'Place',

			'attribute'=>'name',

			'fields'=>array('name','id_place'),

		),

	);

}

And the clientside call is made like this :


<?php

	$this->widget('zii.widgets.jui.CJuiAutoComplete', array(

		'model'=>Place::model(),

		'attribute'=>'name',

		'sourceUrl'=>array('event/aclist'),

		'options'=>array(

			'minLength'=>'2',

			'showAnim'=>'fold',

			'select' => 'js:function(event, ui) { 

        				$("#Place_id_place").val(ui.item["id_place"]);

        			}',

			),

			'htmlOptions'=>array(

       			'style'=>'height:20px;'

		),

	));


	echo $placeForm->hiddenField(Place::model(), 'id_place');

?>

Lastly, here is the json I’m getting back in the browser :


<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 3.2//EN">

<html>

<head>

<title></title>

</head>

<body>

[{"name":"Bataclan","id_place":"1"}]

</body>

</html>

As you can see, the code is quite simple. I’m just wondering why json isn’t used by the plugin…

Well I guess the HTML wrap up is what’s causing the issue. Any idea on how prevent Yii from adding that ?

I tried to add a layout=‘none’, but it didn’t work…