Yii URL in Java script

Dear All ,

I am trying to send parameters to CJuiAutoComplete and found the below answer in the forum




<?php 


echo CHtml::dropDownList('dr',null,array('se', 'sel2', 'Item3'));


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

            'name'=>'test1',

            'options'=>array(

                        'search'=>"js:function(){alert('teste');

                        

                        $('#test1').autocomplete({

                                        source : 'http://localhost/kmcms/site/autocomplete?newparam=' + $('#dr :selected').text()

                        });


                        

                        }"

                        

            ),

        ));

?> 

But in the above source is hard coded , Can I know the correct syntax to use without hard coding URL , some thing similar to




CController::createUrl('site/autoCompleate?newparam=') 

Thanks for your help

Regards

Yii Fan

Perhaps something like this?




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

  'model'=>$model,

  'attribute'=>'distributor_id',

  'source'=>$this->createUrl('distributor/AutoCompleteLookup'),

  'options'=>array(

    'minLength'=>2,

    'showAnim'=>'fold',

  )

));	



Hi rei,

Thanks for your response , but with this approach I can not send my selected dropdown field to controller . If you look at my code I am also sending dropdown values to the controller .

Regards

Kiran

Sorry I didn’t see that. This may help you. Don’t know if there is a better solution, though. :unsure:




'source'=>'js: function(request, response) {'. 

   CHtml::ajax(array(

      'url'=>array('site/autoComplete'),

      'type'=>'GET',

      'dataType'=>'json',		

      'data'=>array(

         'newparam'=>"js: $('#dr :selected').text()",

	 'term'=>"js: (value of this autocomplete field)"

      ),

      'success'=>"function(data) {

         response($.map(data, function(item) {

	    return {

		label: item.label,

		value: item.value

	    }

	 }));

      }"						

   )).

'}'



Thank You rei . That helped me and that is a wonderful solution .

Here is the one that worked




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

            'name'=>'test1',

           'source'=>'js: function(request, response) {

		       $.ajax({

		           url: "'.$this->createUrl('myAutoComplete/autoCompleate').'",

		           dataType: "json",

		           data: {

		               term: request.term,

		               type: $("#type").val()

		           },

		           success: function (data) {

		                   response(data);

		           }

		       })

 			}',




        ));

Once again Thanks

Regards

Yii Fan