【问题标题】:Yii - CHtml::ajaxLink inside a div loaded with an CHtml::ajaxLinkYii - 加载了 CHtml::ajaxLink 的 div 中的 CHtml::ajaxLink
【发布时间】:2014-01-20 20:33:07
【问题描述】:

我有一个包含 10 个项目的侧边栏:

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

这会加载 10 个链接,点击后将它们各自的链接发送到:

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

现在,这很好用——这次除了 ajaxLink。它有时会运行此脚本 1 次,有时会运行 5 次。有时第一个请求(来自侧边栏,即使它没有被点击)会接管第二个。

直播网址:

有人知道吗?

【问题讨论】:

    标签: php jquery ajax yii


    【解决方案1】:

    为您的 ajax 链接分配一个随机 ID。

    在您的 ajaxLink html 选项中输入:

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

    【讨论】:

    • 哇!谢谢。我一直把它们放在错误的地方(在 createUrl() 内)。谢谢大佬!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-08-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多