Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
yiiajax加载整个页面而不是我的输出_Ajax_Yii - Fatal编程技术网

yiiajax加载整个页面而不是我的输出

yiiajax加载整个页面而不是我的输出,ajax,yii,Ajax,Yii,我在使用ajax时遇到了一个问题。 我以在项目中使用依赖下拉列表测试ajax为例 表单代码(protected/views/game/_Form.php): Ajax正在工作,但如果调试器发现了该代码,那么放在我的Game_season_Game_stage select中的就是我网站整个页面的html代码,如 <select name="Game[season_game_stage] id="Game_season_game_stage"> <meta http-eq

我在使用ajax时遇到了一个问题。 我以在项目中使用依赖下拉列表测试ajax为例

表单代码(protected/views/game/_Form.php):

Ajax正在工作,但如果调试器发现了该代码,那么放在我的Game_season_Game_stage select中的就是我网站整个页面的html代码,如

<select name="Game[season_game_stage] id="Game_season_game_stage">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    ...
    <div class="container" id="page">...</div>

只需在输出后退出即可

public function actionSelectGameStages()
{
    // Do stuff
    ...

    exit;
}

为什么不直接在视图中使用dropDownList

是的


谢谢您的回答!我找到了解决办法

在protected/views/game/_form.php中,我错过了“url”键,并重命名了game/selectGameStages

<?php 
    echo $form->dropDownList($model, 'season_id', Season::getSeasonsList(), array(
        'ajax' => array(
            'type'=>'POST',
            'url' => CController::createUrl('game/selectGameStages'),
            'update'=>'#Game_season_game_stage'
            )
        )
    ); 
?>

谢谢你的帮助

由于您的布局,整个页面正在加载

在控制器中,检查此调用是否为ajax调用,将布局更改为没有这些标记的布局,或者最好为ajax调用创建一个布局

if($this->getIsAjaxRequest())
      $this->layout = '//ajax'; // ajax layout

我需要根据第一个下拉列表中的选定值从其他表生成选项。请添加要更新的代码。
<?php echo CHtml::dropDownList('listname', $select, 
              array('M' => 'Male', 'F' => 'Female'),
              array('empty' => '(Select a gender)'));
<?php 
    echo $form->dropDownList($model, 'season_id', Season::getSeasonsList(), array(
        'ajax' => array(
            'type'=>'POST',
            'url' => CController::createUrl('game/selectGameStages'),
            'update'=>'#Game_season_game_stage'
            )
        )
    ); 
?>
public function accessRules()
    {
        return array(
            array('allow',  // allow all users to perform 'index' and 'view' actions
                'actions'=>array('index','view', 'selectGameStages'),
                'users'=>array('*'),
if($this->getIsAjaxRequest())
      $this->layout = '//ajax'; // ajax layout