Newly created ajax links doesn't work

I have a div named __cart. This div contains the product list along with tiny + and - buttons. With these the user can increase / decrease the quantities by ajax. This works fine for the existing products, the problem comes when new products are added - by ajax - to this div!

The links look like this:




CHtml::ajaxLink(CHtml::image('/images/minus.png', '')), array('addtocart?id='.$data[0].'&qty=-1'), array('update'=>'#__cart'), array('id'=>'tiny_minus'.$data[0]));

CHtml::ajaxLink(CHtml::image('/images/plus.png', ''), array('addtocart?id='.$data[0].'&qty=1'), array('update'=>'#__cart'), array('id'=>'tiny_plus'.$data[0])).



The problem comes when the user adds a new item to the cart. The cart is updated via ajax and the new products generate new id’s. The ajax link doesn’t work for new items since there is no script for them in the bottom of the old html document body.

How to solve this problem?

How do I generate script(s) for the new ajax links and how do I include these in the old html document body???

hi

CHtml::ajaxLink(CHtml::image(’/images/plus.png’, ‘’), array(‘ControllerName/ActionName?id=’.$data[0].’&qty=1’), array(‘update’=>’#__cart’), array(‘id’=>‘tiny_plus’.$data[0]))

controller missing before addtocart (controller/action).

http://www.yiiplayground.cubedwater.com/index.php?r=AjaxModule/ajax/ajaxRequest

Thanks

When the controller is missing, it is replaced with the current. It’s working fine. But the problem isn’t this. The problem is that the newly created ajax link doesn’t has it’s corresponding script on the bottom of the html body. Is there a way to include script in the updated div?

Wondering if you ever found the solution to this. I’m having the same problem.

Hi

Did you added this action in access rules in controller??

Yes. It has nothing to do with the controller.

I was debugging the application and for some reason (I haven’t found out why) the following line, in CHtml class when self::clientChange is called within ajaxLink, is not kicking in:

$cs->registerScript(‘Yii.CHtml.#’ . $id, “jQuery(‘body’).on(’$event’,’#$id’,function(){{$handler}});”);