Ajax question

Hello, I am experienced with AJAX, but not with using it within the Yii framework. Simple scenario: if I have a bunch of checkboxes (created with CHtml::checkBoxList), and I want it so that when a user clicks a checkbox, it makes an ajax call - how would I go about starting this? Thanks.

You can do it same way as you did before.

CHtml::ajax is an helper that write the ajax code you are used too.

It adds some features like url formatting and some more options. Take a look at the doc for complete reference, anyway you can always use your methods.

Okay so far I have:




echo CHtml::checkBoxList(

	'attendance',

	$this->getAttendees($model->id),

	Chtml::listData(Users::model()->findAll(),'id','fullName'),

	array(

		'ajax' => array(

			'type'=>'POST',

			'data'=>"id=<img src='http://www.yiiframework.com/forum/public/style_emoticons/default/huh.gif' class='bbc_emoticon' alt='???' />???", //Don't know what to put here

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

			'update'=>'#attendee_status',

		)

	)

);



Basically it works as far as calling the appropriate controller action and all that, but I want to send as data to that function the value of the clicked checkbox (and whether it was checked or unchecked). Also, when I click a checkbox it doesn’t get checked/unchecked for some reason. Any help is appreciated, thanks.

You can use JS code in your params like this: "js:function(){$(".something").val();}"

I’m just having a hard time getting this to work:




'data'=>"id=js:function(){return 'aaaa';}",



This just passes the string “js:func…” as the id, what is the proper syntax for passing “aaaa” as the id? I’ve tried so many variations, including the format:




'data'=>"({id : \"aaaa\"})",






'data'=>"({id : js:function(){$(\"#attendee_status\").val();}})" //yes there is a value in #atte...



Neither of those do anything. Any help is appreciated, thanks.


data'=>"js:{id: $(\"#attendee_status\").val();}"

yeh that’s not working either, oh well

just to reiterate what I’m looking for (maybe if someone has done this before): using a CHtml::checkBoxList, have the ability to call an ajax function whenever someone clicks on one of the check boxes. Of course, the data sent to the controller should include the id of the checkbox so I can do something based on that. That is the part I am having trouble with - sending that id. Thanks.

Thanks samdark, this is my solution:


'data' => "js:{id: myarray[i]}",

Markus

i have the same problem.Can you post the code?