$.ajax(), RenderPartial, Javascript


I have a page that loads via an Ajax renderPartial another page where there are inside of JavaScript and ajaxsubmitButton

This is the code to invoke

        $this->renderPartial('_modifica_elemento', array("model" => $model, "media" => $file),false, true);

Every time you call, the javascript files are loaded by adding a timeStamp … You can use the cache?

If I call the renderPartial 10 times for example ajaxSubmitButton calls me 10 times the action associated to her!

The action returns a JSON

Thanks to all

I am not a javascript pro but I assume that an event is attached every time you render an ajax button into your view. Since 1.1.9 you can choose to use live events or not. CHtml reference:

Hope it helps

P.S.: Did you set the scriptMap entry for the script that is downloaded twice to false? Like when jquery is downloaded again and again you could do:

Yii::app()->clientScript->scriptMap['jquery.js'] = false;

in the controller action

Hi thanks you,

now i make one call but not refresh my image ( i retrieve my image by Json)

 $(".foto_profilo .image_login").attr({ 

                                        src: data.div,

                                        title: "jQuery",

                                         alt: "jQuery Logo"


but i call always file.js

This code doesn’t tell you anything. Any javascript errors on the client side? JQuery not loaded? What is file.js? When setting the scriptMap entry for JQuery to false you tell Yii to not load JQuery. So only disable it when you are sure that it was loaded already. If not your image refresh script won’t work

  1. First request -> load page and JQuery

  2. Ajax request to same action -> use scriptMap to prevent JQuery from being downloaded again

i haven’t error javascript.

The javascript that i want load is Jquery and jCrop, and custom file

if i use

Yii::app()->clientScript->scriptMap['jquery.js'] = false;

my renderPartial doesn’t works

the problem is also that anytime i call my render and click on ajaxsubmitbutton, i create like "queue" of Action…

Thanks a lot

Antonio wrote two wiki entries about these type of problems. They may be helpful:

  1. http://www.yiiframework.com/wiki/231/avoiding-duplicate-script-download-when-using-cactiveform-on-ajax-calls

  2. http://www.yiiframework.com/wiki/236/avoiding-duplicate-script-download-when-using-ajax-calls-to-render-different-views

The problem mentioned in article 2 seems like the one you have