首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >cakephp传递选择值ajax

问cakephp传递选择值ajax
EN

Stack Overflow用户
提问于 2014-02-07 07:39:58
回答 1查看 1.5K关注 0票数 1

我有两个选择按钮,并希望过滤记录,当用户选择任何选项时,我必须触发一个事件并将按钮的值传递给控制器的操作。我的代码如下所示

视图

代码语言:javascript
复制
<?php echo $this->Form->create('Employee'); ?>
   <fieldset>
      <div class="pure-control-group">
      <?php echo $this->Form->input('designation', array("label" => "Designation",'type' => 'select', 'id'=>'DesignationType','options' => $settings,'empty'   => 'select'));?>

      <?php echo $this->Form->input('district', array("label" => "District",'type' => 'select', 'id'=>'districtType','options' => $district,'empty'   => 'select'));?>
      </div>
  </fieldset>
<?php echo $this->Form->end(); 

   $this->Js->get('#DesignationType')->event('change',
    $this->Js->request(array(
        'controller'=>'employees',
        'action'=>'getByCategory'
        ), array(
        'update'=>'#success',
        'async' => true,
        'method' => 'post',
        'dataExpression'=>true,
        'data'=> $this->Js->serializeForm(array(
        'isForm' => true,
        'inline' => true
            ))
        ))
    );
    ?>
 <div id="success"></div>

控制器

代码语言:javascript
复制
public function getByCategory(){
      $design_id =$this->request->data['Employee']['designation'];
      $district_id =$this->request->data['Employee']['district'];         
      $this->layout = 'ajax';
}

当我单击“指定”时,我就可以得到指定的值,但不能得到地区.And的值,然后出现错误。

未定义索引:地区APP\Controller\EmployeesController.php,第18行

那么,如何才能得到区域的价值;

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-02-07 09:27:30

尝试在数据变量中发送form id。那是

试试这个:

代码语言:javascript
复制
$data = $this->Js->get('#YourFormId')->serializeForm(array('isForm' => true, 'inline' => true));    
$this->Js->get('#DesignationType')->event('change',
$this->Js->request(array(
   'controller'=>'employees',
   'action'=>'getByCategory'
   ), array(
   'update'=>'#success',
   'async' => true,
   'method' => 'post',
   'dataExpression'=>true,
   'data'=> $data
   ))

);
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/21621970

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档