Hi…
Before I ask my question , let me describe my situation and my code first, thanks for your patient.
This is a snippet from my controller which is requested use AJAX request.
EXAMPLE ONE
echo CJSON::encode(array(
'status'=>'success',
'div'=>'Tambah Universitas Berhasil',
'ddContent'=>$this->renderPartial('universitiesData',array('data'=>$data),true),
));
This is my universitiesData view, which is intended to fill a drop down that i want to.
echo CHtml::tag('option',array('value'=>-1), CHtml::encode('- - Pilih Universitas - -'),true);
foreach($data as $value=>$name)
{
echo CHtml::tag('option',array('value'=>$value), CHtml::encode($name), true);
}
EXAMPLE TWO
echo CJSON::encode(array(
'status'=>'success',
'div'=>'Tambah Universitas Berhasil',
'ddContent'=>$this->generateUniversitiesData(), // <--- This is the point of difference !!!
));
This is generateUniversitiesData() method
private function generateUniversitiesData()
{
$univs = University::model()->findAll(array(
'condition'=>'status=1',
));
$data = CHtml::listData($univs,'id','name');
echo CHtml::tag('option',array('value'=>-1), CHtml::encode('- - Pilih Universitas - -'),true);
foreach($data as $value=>$name)
{
echo CHtml::tag('option',array('value'=>$value), CHtml::encode($name), true);
}
}
I have done successfully use example one approach. But I want to ask Why the second example can’t worked properly.
When I observed from firebug i got that drop down content is on the outside of the JSON object ( so the ‘ddContent’ had a null value, but if i follow the first approach the result is in the appropriate place ( inside JSON object )
Is there anyone could explained about this ?
Thanks a lot before
God Bless You