Mave
Mave

Reputation: 2516

Yii - CHtml::ajaxLink inside a div loaded with an CHtml::ajaxLink

I have a sidebar with 10 items in them:

foreach(Class::model()->findAll() as $class) { ?>

 <li><?= CHtml::ajaxLink(CHtml::image('http://my.domain.com/' . strtolower($class->name) . '.png') . $class->name, Yii::app()->createUrl('wearable/ajaxUpdate', array('type' => 'class', 'class' => $class->id)), array('update' => '#data'));
}

This loads in 10 links where upon clicked sends their respective links to:

$this->renderPartial('_ajaxUpdate', $data, false, true);

_ajaxUpdate:

if(isset($_GET['class']) && $_GET['type'] == 'class' && is_numeric($_GET['class'])) {
 foreach(ItemClass::model()->findAllByAttributes(array('class_id' => $_GET['class'])) as $itemClass) {
  $item = Item::model()->findByAttributes(array('id' => $itemClass->item_id));

        <div class="gallery-image">
            <?= CHtml::ajaxLink(
                    CHtml::image('http://my.domain.com/images/' . $item->url), Yii::app()->createUrl('item/ajaxUpdate', array('type' => 'item', 'item' => $item->id)), array('update' => '#data'));

        </div><?php
    }
}

Now, this works beautifully - apart from the ajaxLink this time. It sometimes runs this script 1 time, sometimes 5. Sometimes the first request (from the sidebar even though it wasn't clicked on) takes over the second.

Live url:

Anyone have any idea?

Upvotes: 0

Views: 842

Answers (1)

Ali MasudianPour
Ali MasudianPour

Reputation: 14459

assign to your ajax link a random ID.

in your ajaxLink html options put:

array('id' => 'some-name-'.uniqid())

Upvotes: 2

Related Questions