Php Yii中的bulidajax

Php Yii中的bulidajax,php,yii,Php,Yii,我需要了解如何用Yii构建Ajax请求。我在Yii网站上搜索,发现以下文章: 我编写了代码并在本地主机上进行了测试?但由于某种原因,它没有起作用 第一次尝试时,我只想做一些简单的事情。我想使用Ajax在我的页面上打印另一个操作的结果。我想要显示的文本是“Hi” 这是该操作的mu代码的外观: 视图/索引 <?php /* @var $this CurrentController */ $this->breadcrumbs=array( 'Current'=>a

我需要了解如何用Yii构建Ajax请求。我在Yii网站上搜索,发现以下文章:

我编写了代码并在本地主机上进行了测试?但由于某种原因,它没有起作用

第一次尝试时,我只想做一些简单的事情。我想使用Ajax在我的页面上打印另一个操作的结果。我想要显示的文本是“Hi”

这是该操作的mu代码的外观:

视图/索引

<?php
/* @var $this CurrentController */

$this->breadcrumbs=array(
        'Current'=>array('/current'),
        'index',
);
?>
<div class="form">

<?php $form=$this->beginWidget('CActiveForm', array(
        'id'=>'users-index-form',
        'enableAjaxValidation'=>true,
)); ?>
<?php
echo CHtml::dropDownList('country_id','', array(1=>'USA',2=>'France',3=>'Japan'),
array(
'ajax' => array(
'type'=>'POST', //request type
'url'=>CController::createUrl('currentController/dynamiccities'), //url to call.
//Style: CController::createUrl('currentController/methodToCall')
'update'=>'#city_id', //selector to update
//'data'=>'js:javascript statement' 
//leave out the data key to pass all form values through
))); 

//empty since it will be filled by the other dropdown
echo CHtml::dropDownList('city_id','', array());


?>


<?php $this->endWidget(); ?>

</div><!-- form -->

控制器

<?php



class CurrentController extends Controller
{



public function accessRules()
    {
        return array(
            array('allow', // allow authenticated user to perform 'create' and 'update' actions
                'actions'=>array('create','update','dynamiccities'),
                'users'=>array('@'),
            ),
        );
    }
public $country_id;
    public function actionIndex()
    {
        $this->render('index');
    }




public function actionDynamiccities() /// Called Ajax
{


        echo CHtml::tag('option',
                   array('value'=>'2'),CHtml::encode('Text'),true);

}  



}

使用id作为

echo CHtml::dropDownList('city_id','', array('id'=>'city_id'));

代码看起来不错。你能在Firebug登记一下吗?查看ajax request triggers.GBD它的工作原理:查看我的结果:您在快照中是否看到
响应标题
?是404GBD,为什么看起来像这样?我不知道!尝试将从
CController::createUrl('currentController/dynamiccities')
获得的URL直接运行到浏览器中。还可以从
config/main.php
echo CHtml::dropDownList('city_id','', array('id'=>'city_id'));