ajax post param

hi there,

how to add extra param for ajax post request,

suppose that i have view like this:




$siswax=siswa_kelas::model()->findAll($criteria);

foreach($siswax as $n=>$siswa): ?>

  <tr class="<?php echo $n%2?'even':'odd';?>">

	<?php 

		$nama=siswa::model()->findbyPk($siswa->nis)->nama_lengkap;

	?>

    <td><?php echo $siswa->no_absen; ?></td>

    <td width='55%'><?php echo $nama; ?></td>

	<?php 

		$nilai=siswa_nilai_tugas::model()->find('nis=:id and tahun=:thn and semester=:sms and id_mapel=:mapel and tugas_ke=:nil',

			array(':id'=>$siswa->nis,':thn'=>$tahun,':sms'=>$semester,':mapel'=>$id_mapel,':nil'=>$tugas))->nilai;

	?>	

	<td>

	<?php 

	//echo CHtml::textField('nilai['.$siswa->nis.']',$nilai);	

	

		echo CHtml::textField('nilai['.$siswa->nis.']',$nilai,array('id'=>'nilai'.$siswa->nis,

                'ajax'=>array(

                    'type'=>'POST',

                    'url'=>array('simpanNilai'),

		   'params'=>array('id_mapel'=>$id_mapel), // is this true ? <---

                    'update'=>'#nick_result'

                )

               )); ?>		

		

	<div id="nick_result">    </div>

	</td>

	

	</tr>

<?php endforeach; ?>

  </tbody>

</table>



and here is my controller:




	public function actionSimpanNilai()

	{

		$id_mapel=$_POST['id_mapel'];

		$tugas=$_POST['tugas'];

		$nilai=$_POST['nilai'];

		foreach ($nilai as $nis=>$nil):

			$sql="update siswa_nilai_tugas set nilai='{$nil}' where 

					nis='{$nis}' and id_mapel='{$id_mapel}' and tugas_ke='{$tugas}'";

			Yii::app()->db->createCommand($sql)->execute();

			echo $sql;

		endforeach;

        //print_r ($nilai);

	}



how to read var $id_mapel from ajax request post?

thanks before

Hey Ahyo… I was wondering if you had been able to resolve this, because i am struggling with the same problem. I know you posted this last year, i hope you still participate in this forum actively. Thank you very much in advance!

In case anybody stumbles into this… its actually quite dumb! Using the ‘data’ option.




<?php echo CHtml::button('button text', array(

	'ajax' => array(

		       'type'=>'POST', //request type

		       'url'=>CController::createUrl('thisAction'),

		       'data'=>'js:jQuery("#users-form").serialize()',

		       'success' => 'js:

		       function(data){ .....  }',

                  ),

	          'dataType' => 'JSON',

	)); ?>



i just changed ajax request to GET




<?php 

        //echo CHtml::textField('nilai['.$siswa->nis.']',$nilai);       

        

                echo CHtml::textField('nilai['.$siswa->nis.']',$nilai,array('id'=>'nilai'.$siswa->nis,

                'ajax'=>array(

                    'type'=>'GET',

                    'url'=>array('simpanNilai?nis='.$nis),

                   // 'params'=>array('id_mapel'=>$id_mapel), // i don't need this

                    'update'=>'#nick_result'

                )

               )); ?>