Using onClick event at Chtml::label, need help

Hi all,

I need to do export file in my side, i have to to use the code below but is doesn’t trigger the controller. Any problem with the code? can anyone give me some advice?

<div onClick="<?php CHtml::ajax(array(




	'success'=&gt;'function(data) {




I think you’ll have to pass an array to createUrl like CController:createUrl(array(‘sell/loadGame’)) to make this work. Use Firebug or something like that to see the ajax requests that are made.

EDIT: I was wrong, sorry. createUrl doens’t take an route array.

I have try to use firebug to check the console, nothing is happen after i click the link.

This works for me:

<div onclick="<?php echo CHtml::ajax(array(





'success'=>'function(data) {}'));?>">Hallo

I am a Test</div>

  1. You have to echo CHtml::ajax,

  2. You have to get rid of the semicolon in your success function and

  3. Set ‘data’

Interesting note: If you don’t set ‘data’ it will automatically be set by Yii with ‘data’:jQuery(this).parents(" form").serialize()});"="" causing a Javascript parsing error. This seems to be a bug

When using CHtml::tag it works even without setting data. This is interesting. But using CHtml::tag is more “Yii’ish” anyway, so you should use this code:

<?php echo CHtml::tag('div',array(





        'success'=>'function(data) {}')