Dynamic Modal View

I want to pop out the content inside the modal but it pops up only on data, same data all the time

ContentController.php




public function actionList()

	{

		$data = array();

		

		$trends=new CDbCriteria;

        $trends->order = 'created DESC';

        

		$trends->addCondition("vid=(SELECT MAX(vid) FROM content WHERE id=t.id)")

		         ->addCondition('type_id >= 2')

		         ->addCondition('password = ""')

		         ->addCondition('category_id = 2')

		         ->addCondition('status = 1');

		

		$trends_list = Content::model()->findAll($trends);

		$pages->applyLimit($trends);

		

		$this->render('all', array('trends_list'=>$trends_list));		

	}



all.php




<?php foreach($trends_list as $content): ?>

<?php $this->renderPartial('//content/_recent', array('content' => $content)); ?>

<?php endforeach; ?>	



_recent.php




<div id="myModal" class="modal hide">

    <div class="modal-header">

      <button class="close" data-dismiss="modal">&times;</button>

      <h3><?php echo $content->slug; ?></h3>

    </div>

    <div class="modal-body">            

        <div id="modalContent">

			<?php echo $content->content; ?>

        </div>

    </div>

    <div class="modal-footer">

      <a href="#" class="btn btn-info" data-dismiss="modal" >Close</a>

    </div>

</div> 

<a href="#myModal" data-toggle="modal" id="<?php echo $content->id; ?>"><?php echo $content->slug;?></a>

<script>


$("a[data-toggle=modal]").click(function() 

	       {   


	           $.ajax({

	               cache: false,

	               type: 'POST',

	               url: "<?php echo $this->createUrl('/' . $content->slug); ?>"+$(this).attr('id'),

	               data: '',

	               success: function(data) 

	               {

	                   $('#myModal').show();

	                   $('#modalContent').show().html(data);

	               }

	           });

	       });

</script>



First you should try to open your ajax url in browser (without modal), and if content is changing as needed this is the problem with modals.

I suppose you’re using bootstrap modal, try to clear data like this:


$('#myModal').on('hidden', function() {

    $(this).removeData('modal');

});

or this (for bootstrap 3):


$(document.body).on('hidden.bs.modal', function () {

    $('#myModal').removeData('bs.modal')

});

check this wiki