Controller: obviously it is just dummy data.
public function actionLoadTemplate(){
echo CJSON::encode(
array(
'extension'=>'6000',
'name'=>"Demo name",
'number'=>"0123456789"
)
);
View:
I have included the three solutions i have tried under the three values returned
<?php
echo $form->dropDownList($model,'template_id',CHTML::listData(Sipconf::model()->findAllByAttributes(array('istemplate'=>'1')),'client_id','name'),
array(
'ajax' => array(
'type' => 'post',
'datatype' => 'json',
'url'=> CController::createUrl('sipconf/loadtemplate'),
'success'=>'function(data){
$("#Sipconf_extension").val(data);
$("#'.CHTML::activeId($model,'name').'").val(data.name);
$("#'.CHTML::activeId($model,'number').'").text(data.number);
}'
)
)
);
?>
Firebug shows that the JSON data being returned is:
{"extension":"6000","name":"Demo name","number":"0123456789"}
the Sipconf_extension field updates with the entire JSON response, but the other two fields do not update correctly.
if i change val(data.name) to val(data) then i get the same JSON response in the text field.