ajaxlink not update [SOLVED]

index view


                 echo CHtml::ajaxLink('<img title="YouTube" src="' . Yii::app()->request->baseUrl . '/images/youtube-icon.png" alt="youtube-icon.png" />',$this->createUrl('displayYouTube'), array('update' => '#youtr'));

                          ?>  </td></tr> 

                        <tr id="youtr"> <?php if ($this->displayYouTube): ?> <td>display something</td></tr> <?php endif; ?>




public $displayYouTube=false;


    public function actionDisplayYouTube(){




i cannot see the update

you will never see the effect of ajax because you are returning true which you cannot see. try in your action the following

public function actionDisplayYouTube(){

         print "success";


but i have a $displayYouTube variable and an if clause in the view

Does the ajax link send the proper informations ?

Is then the given response the one you need ?

And finally, I’m not sure that assigning your id “youtr” to the <tr> tag will update the innerHtml of the <td> tag …

(btw, I’m absolutely not a jax expert)

the ajax link simply call the action,what i need is to update the tr with the id="youtr" after the action change the variable to show the content,i have tested with a div inside td but is the same result

this is how ajax calss should work ::)

does this help you ?

In a grid view, if ‘decollage’ field is null (db defaults), an ajaxLink with #id 'deco4, ‘deco2’ … is displayed, otherwise the $data->decollage value is shown.






					array("decollage", "id"=>$data->id),


						"success"=> "function(responseText) {







The controller action:

it checks the ajaxRequest, load model, set the value and echo the result wich will replace (note the javascript ‘replaceWith’) the ajaxLink


	 * Set the decollage of a particular model.

	 * @param integer $id the ID of the vol model to be set as decollage


	public function actionDecollage($id)







		echo $now;



ok i understand but tell me what for the parameter update with the id??

each ajaxLink has his self id (#deco1, #deco2 and so on) :


this link is replaced by ajax:

"success"=> "function(responseText){



for simple update, use "update" instead of "replaceWith" (I think so )

ok.But how to run the code

<?php if ($this->displayYouTube): ?>...

with the variable changed?



echo CHtml::ajaxLink('<img title="YouTube" src="' . Yii::app()->request->baseUrl . '/images/youtube-icon.png" alt="youtube-icon.png" />',


// this should work ... give a try


// or maybe that can work too ?

array('update' => '#youtr'));



<tr id="youtr"><td>your initial content</td></tr> 


in your controller:

public function actionDisplayYouTube(){

$result = "<td>What ever you want to display</td>";

echo $result;


thank you

Be carefull I’ve just modified the code.

yes i know but i understood what you mean.its just an example

If you have the woking solution post it here and mark the topic as [SOLVED], this might help someone ;)

ok.just another issue.supposed i want to update a div id on layout main.php instead the index.php,how to do in the update?

btw: processing ad I suggest doesnt follow a strict MVC design because of creating html stuff in the controller, so there must be for sure a better solution, but I don’t know how to deal with that …

it works fine since the id is on page.Thanks

just change #youtr with #your_div_id