Yii Framework Forum: ajax+clientScript - Yii Framework Forum

Jump to content

  • (3 Pages)
  • +
  • 1
  • 2
  • 3
  • You cannot start a new topic
  • You cannot reply to this topic

ajax+clientScript Definitive solution for all clientScript problem in ajax request Rate Topic: ***** 12 Votes

#41 User is offline   JimJ 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 3
  • Joined: 15-June 11
  • Location:Atlanta

Posted 25 June 2011 - 10:48 AM

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!
Free Markets for Free People!
0

#42 User is offline   Revelis Luc Bonnin 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 18
  • Joined: 23-May 11
  • Location:Earth

Posted 14 August 2011 - 08:27 AM

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
1

#43 User is offline   eirikhm 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 66
  • Joined: 06-October 08

Posted 26 August 2011 - 04:01 AM

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;
		}
    }


0

#44 User is offline   eirikhm 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 66
  • Joined: 06-October 08

Posted 29 August 2011 - 03:12 AM

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...-ajax-requests/ for more info and code.
0

#45 User is offline   mbabineau 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 31
  • Joined: 07-June 11
  • Location:San Diego, CA

Posted 08 December 2011 - 10:03 PM

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
0

#46 User is offline   wsw36 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 23
  • Joined: 31-March 11
  • Location:Surabaya

Posted 29 March 2012 - 04:56 AM

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

#47 User is offline   shayan 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 53
  • Joined: 10-October 11

Posted 18 September 2012 - 03:24 PM

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?
0

#48 User is offline   mem 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 46
  • Joined: 16-December 11

Posted 27 September 2012 - 06:39 AM

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
0

#49 User is offline   Reinier 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 10
  • Joined: 24-April 12

Posted 10 November 2012 - 06:22 AM

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
0

#50 User is offline   Ankit Modi 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 881
  • Joined: 19-February 13
  • Location:India

  Posted 19 February 2013 - 06:53 AM

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,
Ankit Modi
Skype : amodi06
0

#51 User is offline   kiel004 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 1
  • Joined: 24-June 13

Posted 25 June 2013 - 02:07 AM

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.
0

#52 User is offline   mplexus 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 5
  • Joined: 19-March 13
  • Location:Greece

Posted 09 August 2013 - 05:42 AM

Thanks for sharing your code, it definitely helped me.

( http://www.yiiframew...1#entry216362My link )
0

#53 User is offline   YiiNewbie089 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 3
  • Joined: 23-September 13

Posted 24 September 2013 - 03:10 PM

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.
0

#54 User is offline   YiiNewbie089 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 3
  • Joined: 23-September 13

Posted 30 September 2013 - 03:46 PM

Nobody can help?
0

#55 User is offline   Ankit Modi 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 881
  • Joined: 19-February 13
  • Location:India

Posted 30 September 2013 - 11:03 PM

View PostYiiNewbie089, on 30 September 2013 - 03:46 PM, said:

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.

Thanks,
Ankit Modi
Skype : amodi06
0

#56 User is offline   YiiNewbie089 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 3
  • Joined: 23-September 13

Posted 01 October 2013 - 03:19 PM

View PostMaggie Q(Ankit Modi), on 30 September 2013 - 11:03 PM, said:

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.
0

#57 User is offline   blaco 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 10
  • Joined: 03-July 12

Posted 24 February 2014 - 02:31 PM

i wonder if this is solved in v2.0 :unsure:
0

#58 User is offline   sammy66 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 3
  • Joined: 28-July 14

Posted 28 July 2014 - 08:11 AM

Is this one still not in 1.1.3 version ?

Because I'm trying reorder my items list and everything is ok, but reloading CGridview js not reloading.
0

Share this topic:


  • (3 Pages)
  • +
  • 1
  • 2
  • 3
  • You cannot start a new topic
  • You cannot reply to this topic

2 User(s) are reading this topic
0 members, 2 guests, 0 anonymous users