【问题标题】:Using Ajax in Yii.?在 Yii 中使用 Ajax。?
【发布时间】:2014-04-16 12:01:45
【问题描述】:

我正在工作门户网站,并有一个搜索模块供雇主搜索应用程序。我想在搜索后使用ajax列出应用程序,将结果列出在同一页面中。我应该怎么做。?,下面是模块的截图。尝试了以下的东西。

//控制器代码//

public function actionSearch()
{
               $model = new SearchEmployee();
               /*Getting Data From Search Form For Processing */

          if (isset($_POST['SearchEmployee'])) {

                $model->attributes = $_POST['SearchEmployee'];

                $category   =  $_POST['SearchEmployee']['category'];
                $skills     =  $_POST['SearchEmployee']['skills'];
                $experience =  $_POST['SearchEmployee']['experience'];

             $ajaxmodel = SearchEmployee::model()->find(array(
            'select' => array('*'), "condition" => "category_id=$category AND key_skills like'%$skills%'AND experience=$experience",

             ));

             if($model==null)
             {
                  Yii::app()->user->setFlash('success', "No Results");
                  $this->renderPartial('search');
             }
             else
             {
                  $this->renderPartial('search', array('model' => $ajaxmodel));
                  Yii::app()->end();
             }

}

// 在视图中,不贴完整代码只是显示ajax结果的代码,//

   <div class="view">

       <h1>Results </h1>

     <div class="view" id="id">

       <h1> Records Display </h1>

       <h4>Name: <?php echo $form->labelEx($model,'skills Required'); ?></h4>
       <h4>Skills: <?php echo $form->labelEx($model,'Skills Required'); ?></h4>
       <h4>Experience: <?php echo $form->labelEx($model,'Skills Required'); ?></h4>
       <h5>&nbsp;&nbsp;<?php echo CHtml::submitButton('VIew Details'); ?></h5>
       </div>

       </div>

这样可以吗...

【问题讨论】:

    标签: php ajax yii


    【解决方案1】:

    在您看来,只需启用 ajax,例如:

    $form = $this->beginWidget('bootstrap.widgets.TbActiveForm', array(
            'id' => 'client-document-form',
            'method' => 'post',
            'action' => $url,
            'enableAjaxValidation' => false,
            'errorMessageCssClass' => 'required_field_text'
        )); ?>
    

    这行enableAjaxValidation =&gt; true也需要在你的操作中为真添加这行$this-&gt;performAjaxValidation($model);

    更新:

    $form = $this->beginWidget('bootstrap.widgets.TbActiveForm', array(
                'id'=>'update-profile-form',
                'enableAjaxValidation' => true,
                'errorMessageCssClass' => 'required_field_text',
                'clientOptions' => array(
                    'validateOnSubmit' => true,
                    'validateOnChange' => false,
                    'hideErrorMessage' => true,
                    'beforeValidate' => 'js:function(form) {
                        return validate.beforeValidate("update-profile-form");
                    }',
                    'afterValidate' => 'js:function(form, data, hasError) {
                        validate.afterValidate(data, "update-profile-form");
                    }'
                ),
    

    【讨论】:

    • Arthur...如何从控制器获取结果以查看页面...您能给我一个简单的解释吗?
    猜你喜欢
    • 1970-01-01
    • 2015-01-26
    • 1970-01-01
    • 1970-01-01
    • 2014-01-30
    • 1970-01-01
    • 1970-01-01
    • 2018-12-15
    • 1970-01-01
    相关资源
    最近更新 更多