Yii Framework Forum: ajaxLink ajaxButton side effect - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

ajaxLink ajaxButton side effect Rate Topic: -----

#1 User is offline   james2010 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 48
  • Joined: 19-February 10

Posted 06 May 2010 - 02:39 PM

Hi got some side effect with ajaxLink and ajaxButton

so just a example

View
  <?php echo CHtml::ajaxLink("Click Me",
		  CController::createUrl('/HelloWorld/next'),
		  array('update' => '#update', 'type' => 'GET')); ?>
		  
		  
		 
<div id="update">
</div>

Controller
$this->renderPartial('next',array(),false,true);

so what happend everything fine link will call view next

ok in view next follow
  <?php echo CHtml::ajaxLink("Click Me 2",
		  CController::createUrl('/HelloWorld/next2'),
		  array('update' => '#update', 'type' => 'GET')); ?>

<div id="update">

</div>


controller
$this->renderPartial('next2',array(),false,true);

view next2

  <?php echo CHtml::ajaxLink("Click Me 3",
		  CController::createUrl('/HelloWorld/next2'),
		  array('update' => '#update', 'type' => 'GET')); ?>



so what happen the first time it works but if i click "Click Me 2"

ajax Link will call next and next 2 .

and if i Click "Click Me 3" the will call next, next2 and next 3
0

#2 User is offline   tri 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 1,651
  • Joined: 20-November 08
  • Location:Stockholm, Sweden

Posted 06 May 2010 - 05:10 PM

View Postjames2010, on 06 May 2010 - 02:39 PM, said:

Hi got some side effect with ajaxLink and ajaxButton

so just a example

View
  <?php echo CHtml::ajaxLink("Click Me",
		  CController::createUrl('/HelloWorld/next'),
		  array('update' => '#update', 'type' => 'GET')); ?>
		  
		  
		 
<div id="update">
</div>

Controller
$this->renderPartial('next',array(),false,true);

so what happend everything fine link will call view next

ok in view next follow
  <?php echo CHtml::ajaxLink("Click Me 2",
		  CController::createUrl('/HelloWorld/next2'),
		  array('update' => '#update', 'type' => 'GET')); ?>

<div id="update">

</div>


controller
$this->renderPartial('next2',array(),false,true);

view next2

  <?php echo CHtml::ajaxLink("Click Me 3",
		  CController::createUrl('/HelloWorld/next2'),
		  array('update' => '#update', 'type' => 'GET')); ?>



so what happen the first time it works but if i click "Click Me 2"

ajax Link will call next and next 2 .

and if i Click "Click Me 3" the will call next, next2 and next 3


This is a complex issue and I think we will have to look forward for a generic solution.
You can search the forum and you will find several threads about this and related issues (have a look in the bug tracker too).

Here's an attempt for just a rough explanation:

On initial load, 1st ajax update, 2nd ajax update, and so on, elements are generated with id's like yt0, yt1, ...
The numbering in each update is independent of the others so id collisions will occur.

Depending on if the fourth parameter to renderPartial is true, additional jQuery stubs will be inserted into the document. For element id's not initially present, the fourth parameter to renderPartial would be needed in order for a event handler to be attached to the newly inserted element. But for resident element id's the document (may?) end up with several handlers attached to the same element id (originally attached to content that is no longer present).

If I got it correctly, without the fourth parameter to renderPartial, elements originally present and replaced with same id's should automatically have the events rearmed by the jQuery.live() functionality. However it seems like this not always(/ever?) work.

If you didn't already try, check what happens if you leave out the fourth parameter to renderPartial.

Otherwise I think you should be able to work around the issue by giving all elements unique id's. E.g:
<?php
  echo CHtml::ajaxLink(
    "Click Me 3",
    CController::createUrl('/HelloWorld/next2'),
    array('update' => '#update', 'type' => 'GET'),
    array('id' => 'some_unique_id')
); ?>

/Tommy
Don't forget to read The Definitive Guide to Yii (en) (sv) | The class reference has the details
0

#3 User is offline   james2010 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 48
  • Joined: 19-February 10

Posted 07 May 2010 - 02:41 AM

yee i think that with the id is a good solution.

thanx a lot
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

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