0

選択した schoolFilter フォームの値を取得し、[SELECTED VALUE HERE] に配置したいと考えています。

$data = $this->Js->get('#SchoolFilter')->serializeForm(array('isForm' => true, 'inline' => true));

$this->Js->get('#SchoolSchoolId')->event(
'change', $this->Js->request(
        array('action' => 'assign_school_ads/', [SELECTED VALUE HERE], array(
            'update' => '#results',
            'data' => $data,
            'async' => true,
            'dataExpression' => true,
            'method' => 'POST'
        )
    )
);

// School Filter
$schoolFilter = $this->Form->create('School', array('id' => 'SchoolFilter');
$schoolFilter .= $this->Form->input('school_id', array('label'=>'Schools', 'empty'=>'- select -');
$schoolFilter .= $this->Form->end();

この質問のバリエーションを見てきましたが、JS Helper の使用を忘れていることを除いて、明確な答えはありません。JS Helper のコンテキスト内で可能ですか? そうでない場合は、通常の JQuery を使用して値を取得し、それを JS Helper に挿入できますか。

4

1 に答える 1

0

次のコードを使用してください:-

$this->Js->get('#SchoolFilter');
$this->Js->event('change', $this->Js->request(array('controller'=>'put-ur-controller-ame-here','action' => 'assign_school_ads'),array('async' => true,'update' => '#results','method' => 'post','dataExpression'=>true,'data'=> $this->Js->serializeForm(array('isForm' => true,'inline' => true)))));

関数はserialize()フォーム データを php アクションに送信するので、どのオプションが選択されたかを確認し、ajax 呼び出しで何を更新するかを決定できます。

フォーム データはアクションで見つかります$this->data(フォームが送信された後のように)。

$this->Js->writeBuffer();body 終了タグの直前にレイアウトに追加することを忘れないでください。そうしないと、すべての ajax コードがページに追加されません。

于 2013-03-14T11:33:52.333 に答える