renderPartial doesnt refresh browser source code


i check whether a picture or a video should be inserted:

(view random.php)

<? if ($task->question_type == 'pic') {?>

   <div class="image_preview">

     <img width="250"  src="<?= Yii::app()->request->baseUrl; ?>/images/tasks/<?= $task->id ?>.jpg" />



   <div class="task_td_picsource">

     <? echo "Source: " . $task->copyright ?>


<? } else {

   $this->renderPartial('/site/videoembed', array('newUrl' => $task->url, 'taskSource' => $task->copyright),     false, true);

} ?>

If user clicks new random Question i render the random.php with:


public function actionRandom() {

        $this->renderPartial('random', array(), false, true);


I call this actionRandom with my javascript function which is definded at the bottom of the view

function randomTask(){


            type: "POST",

            url: "<?= $this->createUrl("site/random") ?>",

            success: function(answer){ 



            beforeSend:  function(){ 


                $("#random_task_content").html("<img src=\"<?= Yii::app()->request->baseUrl ?>/images/loading.gif\" alt=\"loading\">");               




#random_task_content is a span around the whole content of random.php. so simply everything should be replaced in this view by the result.

Works great. But if a video appears, the source Code of the picture case is still available (not visible at the frontend) if i click in firefox watch source code and the browser interprets it. I have some javascript youtube api to controle my videos. and if a picture appears this javascript is still available, firefox interpets this and throws javascript errors in firebug. I use replaceWith which should replace the whole content. but it doesnt.

Why? i tried everything. Change replaceWith with html, set renderPartial 3rd and 4th variable to all possibilities. but the source of video is still available if a picture appears.

Have you looked at what kind of headers the server and script are setting, is it telling the browser to cache the page?

how can i set this? and where do i look up?

I suggest you to insert new element in this way:

$('#elem').append('<div id="#yourVideoOrPic">...</div>');

and then remove it with


I know that you tired html() instead of replaceWith(). But replaceWith() replaces the span element you have … therefore you won’t have the span element after your first request. ( So my guess is that you want html().

i solved it with a simple try catch block in the js code… im such an idiot… :)

but thx for the answers. helped me as well for other problems.

great site here. love it!