2012-02-29 26 views
0

我設法在cakephp中獲得了ajax函數,該函數在單擊下拉列表來填充另一個下拉列表時調用它。我無法獲得的一個領域是傳遞第一個下拉列表的id值,以便我可以進行查找。cakephp在ajax中傳遞下拉值

我希望通過公司編號,以便我可以得到相關的僱員。

謝謝。

檢視:

<?php 
$this->Js->get('#MonthlyReturnCompanyId')->event('change', 
$this->Js->request(
    array(
     'controller'=>'MonthlyReturns', 
     'action'=>'getemployees', 
    ), 
    array(
     'update'=>'#test', 
     'async' => true, 
     'method' => 'post', 
     'dataExpression'=>true, 
     'data'=> $this->Js->serializeForm(array(
      'isForm' => false, 
      'inline' => true 
     )) 
    ) 
) 
); 
?> 



     echo $this->Form->input('company_id' , array('empty' => true)); 

回答

0

簡單地傳遞在動作請求相同的COMPANY_ID作爲重定向 即完成:

$this->Js->request(
array(
    'controller'=>'MonthlyReturns', 
    'action'=>'getemployees',$company_id), 
array(
    'update'=>'#test', 
    'async' => true, 
    'method' => 'post', 
    'dataExpression'=>true, 
    'data'=> $this->Js->serializeForm(array(
     'isForm' => false, 
     'inline' => true 
    )) 
) 
) 
);