I'm trying to show data based on input text.
I've created ajax-enabled input:
echo CHtml::textField("input_tracking",'',array('id'=>'input_tracking','ajax' => array(
'type' =>'POST',
'url' => CController::createUrl('report/getTracking'),
'update' => '#tracking_result',
'data' => 'html'
)));
But it sending empty $_POST. What I'm doing wrong?
My controller code:
$data=MyModel::model()->findAll('tracking=:input_tracking',
array(':input_tracking'=>(int) $_POST['input_tracking']));
$data=CHtml::listData($data,'id','name');
foreach($data as $value=>$name)
{
echo CHtml::tag('option',
array('value'=>$value),CHtml::encode($name),true);
}
Your ajax call is quite wrong. You dont pass any data to controller, thats why POST is empty. Should be like this:
'ajax' => array(
'type' => 'POST',
'url'=>$this->createUrl('report/getTracking'),
'update' => '#tracking_result',
'data'=>array('input_tracking'=>'js:this.value',),
//If this wont work replace update with success function
'success'=> 'function(data) {
$("#tracking_result").empty();
$("#tracking_result").append(data);
} ',
)));
Your controller is fine. Hope this was helpfull.
Can you please try it without the 'data' array index and tell us what happens?
You can take a look at this wiki to accomplish something like what you are trying to do. http://www.yiiframework.com/wiki/24/