ajax+clientScript

Thanks a bunch Zaccaria!

I’ve been helped a great deal studying several of your posts and articles.

I don’t get why some sort of fix hasn’t been incorporated in the framework, but your fix makes it possible for me to use cJuiAutoComplete inside cJuiDialog!

I don’t know if it could help but for in my app, i’ve a customized layout/main.php. I inserted my specific jquery.js lib instead of using


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

        $cs->registerCoreScript('jquery',CClientScript::POS_BEGIN);



So i double insert jquery. For some requests (such as several zii widgets), loader twice jquery resets some objet and generate a "$.param.querystring is not a function" js error client side.

Loading only once jquery fixed the issue for me.

Hope it could help

We have made a custom way to handle a case that’s somewhat related. It’s tied up to jquery mobile, but should be easy to modify to a usual website. jQuery Mobile expects a returned page over ajax to be wrapped in a DIV, and any script outside this div is not usable for us, hence the wrapping. Basically, we never enable processOutput in any of our renders, and this method ensures that scripts are returned.

Usage in controller:





$widget = $this->renderPartial('widget',array(),true); // return contents, no processOutput


$this->renderPage('myview',array('items' => $items,'widget' => $widget),array('id' => 'my-page'));




Implementation:




public function renderPage($view,$params = array(),$options = array(), $return = false, $process = true){

        if (!isset($options['id']))

        {

            $options['id'] = $this->id .'-'.$this->getAction()->id;

        }


        if (!isset($options['data-role']))

        {

            $options['data-role'] = 'page';            

        }

        // page div wrapper for jquery mobile

        $html  = "<!-- page {$options['id']} -->\n";

        $html .= CHtml::openTag('div',$options)."\n";

        // only process if this is an ajax request

        $html .= $this->renderPartial($view,$params,true,Yii::app()->request->isAjaxRequest);

    	$html .= CHtml::closeTag('div');

        $html .= "\n<!-- // page {$options['id']} -->";

  

        // if we do not have a ajax request, render with layout (will also process)

        if (!Yii::app()->request->isAjaxRequest)

        {

    		Yii::trace('running renderText');

    		$html = $this->renderText($html);

        }

 

		if ($return){

		    return $html;

		}

		else

        {

		    echo $html;

		}

    }




I liked the idea blux had on the second page, but doing special server-side work really didn’t appeal to me. My solution is to attach to jQuerys filtering methods and do about the same magic there.

Check http://www.eirikhoem.net/blog/2011/08/29/yii-framework-preventing-duplicate-jscss-includes-for-ajax-requests/ for more info and code.

Cool, got this working today…I’ve got a page that loads JS stuff via ajax and spent most of the day trying to figure out why it wasn’t working.

Does anyone know if this has a bug # I can track or if it’s going to be fixed in 1.1.9?

Thanks,

Matt

thank you very much zaccaria, using your script I could finally overcome the problem when I need to update the CTreeview. :)

i have a gridview column with scripts.

i want to render script on ajax grid view. i think i can’t use zaccaria solution because yii create renderpartial by it self.

we have any official patch for this or better solution? i searched forum many times and this is a usuall issue.

and is there any intention to fix this by Yii developers?

I have a question that I didn’t get, but perhaps I’m missing something obvious:

Why should we create a ZController ?

Can’t we simply use Controller for that propose avoiding creating yet another controller ?

Thanks

Thank you so much!

After searching for hours I finally came up with the idea that this problem should be some bug in Yii and then this tutorial/solution came up!

You made my day :D

Hi,

please change the the button id in unique it’s solved.

not think more…it’s run to me.

Best Regards,

Ankit Modi

Thanks for the workaround! worked for me if there was only one subview. problem is there are 2 subviews.

the solution only worked for one of the subviews. Does this have something to do with the ID’s? also the log says that jQuery is undefined.

Thanks for sharing your code, it definitely helped me.

( http://www.yiiframework.com/forum/index.php/topic/45950-gridview-update-through-ajax-works-only-the-first-time/page__p__216362__fromsearch__1#entry216362My link )

Hello,

first iam a newbie to yii, so please be patient :)

I have the following problem:

I have several controllers which will be called through ajaxlinks. For example home/index, news/index …

Let’s say home/index only includes static content. Now when i change the controller through an Navigation ajaxlink to the controller news/index which includes a CListview with Pagination and ajaxUpdate = true, the pagination with ajax doesn’ t work. It even seems that the css is not properly includes, because the pagingation links are displayed in liststyle.

In the news controller i used the ZController extension from Zach for rendering ajax requests, which solved for me the duplicate ajax requests.

If i call the controller directly news/index with the "renderPartialWithHisOwnClientScript" method from ZController from Zach, the ajax pagination works and also the css is properly working. The css and ajax pagination works also fine, if i click on an pagination link for the first time

If i use the "renderPartial" method i works fine, but then i got the duplicate ajax requests in CListview.

I think the problem is, that while using the "renderPartialWithHisOwnClientScript" method the needed jquery for Clistview pagination is not loaded.

Can anyone help me with my problem?

Thx in advance.

Nobody can help?

Hi,

Just you can pass the ProecessOutput when page render

like


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

or


$this->renderPartial('index',array('model'=>$model),false,true); //false,true ProecessOutput.

That don’t work because i use the Zcontroller from Zach to avoid the duplicate ajax requests. The statement for the ProcessOutput is ignored when using the renderpartialwithownscript method.