symfonyフレームワークを初めて使用しています。 states
選択ボックスで行われた選択に基づいて、city_id
フォームフィールドに値を入力しようとしています。symfony 1.4(フォームフィールドの母集団)でajaxを使用する方法
私はGETSTATESという名前actions.class.php
ファイルに新しいメソッドを作成した()
ここにそれのためのコードです。 JSONを介し
$('#users_states').change(function(){
populateSelectBox('users_city_id', 'get', '<?php echo url_for('states/getCities/'); ?>', {stateId:$(this).val()})
});
機能populateSelectBox単に反復とcity_id
フォームフィールドに移入:状態変化イベントに
public function executeGetCities(sfWebRequest $request)
{
$this->forwardUnless($query = $request->getParameter('stateId'), 'users', 'index');
$this->states = Doctrine_Query::create()
->from('States s')
->where('s.id = ?', array($request->getParameter('stateId')));
if($request->isXmlHttpRequest())
{
echo json_encode($this->states);
}
}
JavaScriptコードは以下の通りです。
しかし、上記のリクエストはエラーを示し、表示getcities
は存在しません。
これを手伝ってください。
おっと...男を働いている)、その結果は... ..うまくおかげで来た:):あなたはfetchArrayを持つ配列を返すことができます –