2014-09-11 64 views
0

我有一个表单元素,它有一个onchange侦听器来通过ajax触发更新另一个元素。Cakephp - 具有多个表单元素的Ajax数据

但是,我希望ajax发布数据包含两个表单元素,而不仅仅是下面显示的元素($ data)。

我试图把我想要序列化的两个元素放在它们自己的嵌套表单中,它会发布这两个元素的值,但是因为这个新表单嵌套在主页面表单cakephp中,所以在提交时忽略这些元素主页面的形式。

$data = $this->Js->get('#Reviewevent'.$index.'score')->serializeForm(array(
    'isForm' => true, 
    'inline' => true 
)); 

$this->Js->get('#Reviewevent'.$index.'score')->event('change', $this->Js->request(array(
    'controller'=>'events', 
    'action'=>'getEventDescription' 
    ), 
    array(
     'update'=>'#'.$index.'Description', 
     'async' => true, 
     'method' => 'post', 
     'dataExpression'=> true , 
     'data'=> $data 
    ) 
)); 

回答

1

原来,你可以使用jquery将一个div序列化,你不需要它是一个表单。我只是把我想发送的ajax请求中的两个元素放在一个div中,而不是嵌套的形式,它工作正常。

$data = $this->Js->get('#'.$index.'ThisDivHasTwoFormElementsInIt')->serializeForm(array(
    'isForm' => true, 
    'inline' => true 
)); 
相关问题