Displaying widgets using AJAX and renderPartial

The app I’m developing has navigation down one side with a main viewport. I’m using code along the lines of the following to load the viewport’s HTML when a link is clicked:

function(event) {




		"success": function(html){






I’ve also overridden the standard render function in my base Controller class like so:

function render($template,$data) {

	if($_GET['ajaxView']) {


	} else {




Now, I like this technique for a couple of reasons. I often middle-click to open links in a new tab, and most AJAX systems would either not function or only show the partial render. This system opens the link normally on a middle click, but opens it with AJAX on a normal click.

The problem I’m having is with how the CSS and JS is tailored for the page which was opened initially, and doesn’t load any more if the page changes. I thus have two solutions I can see:

[list=1][*]Attach all the CSS and JS I could possibly need when the page first loads.

[*]Attach the CSS and JS required for each ajax load to that page.[/list]

Now, I like 1 as it’s a: simpler and b: decreases the load of subsequent ajax requests. I’m unsure exactly how to ensure Yii attaches the desired CSS and JS for each render, however.

Anyone have ideas on how best to do this?

Is the problem is what you are thinking about to make the solution better or are you dealing with the bug. I think if you choose to do failsafe for middle-click then the required CSS/JS has to be loaded with the page.

You may also want to have a look at CHttpRequest’s getIsAjaxRequest() so you can remove &ajaxView=1.

Well I have the same problem, but no one have answered my post, or told me if there is a bug or how to include all the CSS or JS.

In my case, I want to load a form into a dialog, the form has widgets in it, the renderPartial(…false,true) loads it fine but the main menu, styles and funcionalities are lost.

This is anoying since I’m a Ruby on Rails developer and there is a fast way to render a file (forms or wathever) without losing the page styles or JS, I mean something like:

$("#dialog-form").html("<%= escape_javascript(render :partial => 'form')%>")

I’m still looking for an answer…

I have same problem and then i just solve.

after render from controller


$data = $this->renderPartial("_form",array(‘rooms’ => $rooms),true,true);


$("#dialog-form").html(<?php echo json_encode($data) ?>);

Hi you can pass a ProcessOutput when page render or renderPartial


$this->render('index',array('model'=>$model),false,true); // false,true is process output..

if you avoid any js so you can just the put below code on controller action or view file

$cs = Yii::app()->clientScript;


        $cs->scriptMap = array(

            'jquery.js'  =>  false,   // prevent produce jquery.js in additional javascript data


I hope it’s some help. :rolleyes: