hi,
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>
<div class="task_td_picsource">
<? echo "Source: " . $task->copyright ?>
</div>
<? } 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:
(SiteController)
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(){
$.ajax({
type: "POST",
url: "<?= $this->createUrl("site/random") ?>",
success: function(answer){
$("#random_task_content").replaceWith(answer);
},
beforeSend: function(){
$("#random_task_content").html("");
$("#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.