I'd like to discuss a common problem that many time I found in topics.

The problem happens everytime that we have to refresh a content with clientscript in an ajax request.

The two instriment that the framework actually provide are:

$this->renderPartial('view', $params)

and

$this->renderPartial('view', $params, false, true)

The first don't works, because all clientScript inside the refreshed content will not work, and the latter don't work, because all client script outside the refreshed div will not work.

By the way, calling the latter make so that ajax request start a strange recursion, the first time 2 request will be send instead of 1, the second 4, then 8 - 16 and so on.

The common workaround (and what I have always done too) was to avoid to use clientscript for this widget, and that means avoiding even to use CJuiWidget, because the register script file, css file and the script itself in the clientscript.

The workaround concept itself is not bad: the main point is that if we have to render a subview, this subview should be complete and contain all the necessary script for work on his own.

Starting from this idea I implemented this patch for the bug: ZController.php(987bytes)Number of downloads: 889

This file extends CController (so you can put in components and edit /components/Contoller.php for extend it).

This extended class provide a method "renderPartialWithHisOwnClientScript", that will render the clientScript of the subView (and ONLY the clientScript of the subView) at the bottom of the subview itself.

It allows you to work normally, without workaround and without hand-creating CJuiWidget, just remember to call this new renderparital and in the normal renderPartial and in the ajaxRequest function.

NOTE: there is still a problem with id, the components with clientScript inside the content to ajax-refresh should still have a unique id in order to not confilct with external components with the same id.

This cannot be fixed with an extension because CHtml::ID_PREFIX is a const and cannot (for now) be edited.

For YiiDevelopers: this file is a small edit in CControler and CClientScript, please check if it break something and include it in the official release. Let's have a talk about how to fix even the id-conflict problem.

I feel that this detail is the last one Yii's week point in client side managment, let's fix it!

This don't work on my case, i got a list of items and two ajax links for each item, add link and delete link, when i click add link it show delete link and then when i click delete link it suposed to show add linkt then i click in the seond time it dont do nothing.

I solved this with a "minor" hack, I placed the JavaScript in the content to be replaced with AJAX without using CClientScript. This way the JavaScript will work even on the elements in the AJAX content. Kinda ugly but I couldn't think of a better solution.

Well, in this case I just 'll wait for yii fix of this problem. And know I just set AjaxUpdate parameter to false for pager and sorting working not within ajax but with GET property and the page refresh all js.

I haven't looked at your code but I want to put a hint here: I have the same issue right now because I want to use Ajax + dialogs for CRUD operations in my CMS. I used renderPartial(..., false, true) too and stumbled over the problem that the jQuery.js was loaded with each Ajax call!

Where is the problem now? jQuery initializes each time and overwrites the existent version. Here an example: Fancybox extends $.fn so you can call methods via $.fn.fancybox.METHOD. When jQuery is loaded a second time this is not possible any more because $.fn.fancybox is undefined.

My solution was that I filter the data directly after the ajax call but before the success method. See dataFilter callback of $.ajax call.

I haven't looked at your code but I want to put a hint here: I have the same issue right now because I want to use Ajax + dialogs for CRUD operations in my CMS. I used renderPartial(..., false, true) too and stumbled over the problem that the jQuery.js was loaded with each Ajax call!

Where is the problem now? jQuery initializes each time and overwrites the existent version. Here an example: Fancybox extends $.fn so you can call methods via $.fn.fancybox.METHOD. When jQuery is loaded a second time this is not possible any more because $.fn.fancybox is undefined.

My solution was that I filter the data directly after the ajax call but before the success method. See dataFilter callback of $.ajax call.

What does the processOutput parameter is to call the CClientScript->render() method in which there is a call to CClientScript->renderCoreScripts(). Here there is any kind of control over the script that are already loaded into the page. So jquery or any other core script can be loaded twice, and this makes developers go crazy.

g3ck0, could you post your code? how have you extended CClientScript? So we can find the best solution among all and then post the problem in the bug tracker.

Hi! zaccaria, could you explain how do you deal with css files? For example CDetailView requires own css files to be included, but it seems like ZController doesn't include them in ajax response. Also suppose we have a page with jquery-ui tabs, where tab content is loaded via ajax and containts DatePicker widget. In this case jquery-ui.js is inlcluded twice: first - on page load for Tabs plugin and second - for DatePicker plugin in ajax response. What should we do with that?