Yii Framework Forum: Ajaxlink Not Working - Yii Framework Forum

Jump to content

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

Ajaxlink Not Working ajax calls made multiply times render partial not working Rate Topic: -----

#1 User is offline   Ruedi 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 9
  • Joined: 25-March 12

Posted 07 October 2012 - 11:41 AM

I have made in layouts/main.php code to render cart as partial:
   $session = Yii::app()->session;
   $cart = Cart::GetCart($session['cart']);

    $this->renderPartial('//layouts/cart', array(
        'cart' => $cart,
    ), false, true );


Then the page is loaded I receive code 2 times in the bottom of the page and in rendered partial section #cart-content:

page bottom:
jQuery(function($) {
$('body').on('click','#yt1',function(){jQuery.ajax({'url':'en/index.php?r=cart/delete&id=0','cache':false,'success':function(html){jQuery("#cart-content").html(html)}});return false;});
$('body').on('click','#yt2',function(){jQuery.ajax({'url':'en/index.php?r=cart/delete&id=1','cache':false,'success':function(html){jQuery("#cart-content").html(html)}});return false;});
...
$('body').on('click','#yt8',function(){jQuery.ajax({'url':'en/index.php?r=cart/clear','cache':false,'success':function(html){jQuery("#cart-content").html(html)}});return false;});
});
/*]]>*/


from /layouts/cart.php:
<script type="text/javascript">
/*<![CDATA[*/
$('body').on('click','#yt1',function(){jQuery.ajax({'url':'en/index.php?r=cart/delete&id=0','cache':false,'success':function(html){jQuery("#cart-content").html(html)}});return false;});
$('body').on('click','#yt2',function(){jQuery.ajax({'url':'en/index.php?r=cart/delete&id=1','cache':false,'success':function(html){jQuery("#cart-content").html(html)}});return false;});
$('body').on('click','#yt3',function(){jQuery.ajax({'url':'en/index.php?r=cart/delete&id=2','cache':false,'success':function(html){jQuery("#cart-content").html(html)}});return false;});
$('body').on('click','#yt4',function(){jQuery.ajax({'url':'en/index.php?r=cart/delete&id=3','cache':false,'success':function(html){jQuery("#cart-content").html(html)}});return false;});
$('body').on('click','#yt5',function(){jQuery.ajax({'url':'en/index.php?r=cart/delete&id=4','cache':false,'success':function(html){jQuery("#cart-content").html(html)}});return false;});
$('body').on('click','#yt6',function(){jQuery.ajax({'url':'en/index.php?r=cart/delete&id=5','cache':false,'success':function(html){jQuery("#cart-content").html(html)}});return false;});
$('body').on('click','#yt7',function(){jQuery.ajax({'url':'en/index.php?r=cart/delete&id=6','cache':false,'success':function(html){jQuery("#cart-content").html(html)}});return false;});
/*]]>*/
</script>


Delete item from the cart is called mutiple times, so the two items deleted.
When the #cart-content is reloaded i get yt0 id for delete link which is stands for add to cart button id.
I have tryed several solutions but they either don't work or delete miltiply times. I can use html options
to set uniqid() ids, but the links does not work, nothing deleted from cart.
Please give me a short path.
Thanks.
0

#2 User is offline   Ruedi 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 9
  • Joined: 25-March 12

Posted 07 October 2012 - 11:52 AM

I have read:
http://www.yiiframew...87/ajax-update/
http://www.yiiframew...e-ajax-request/
http://www.yiiframew...-does-not-work/
http://www.yiiframew...efresh-problem/
and other
0

#3 User is offline   Maurizio Domba Cerin 

  • Yii - Yesss It Is !!!
  • Yii
  • Group: Yii Dev Team
  • Posts: 4,355
  • Joined: 12-October 09
  • Location:Croatia

Posted 07 October 2012 - 11:58 AM

There was a similar problem in the blog demo application... check this issue for a possible solution and explanation - https://github.com/y.../yii/issues/148
Find more about me.... btw. Do you know your WAN IP?
0

#4 User is offline   Ruedi 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 9
  • Joined: 25-March 12

Posted 07 October 2012 - 12:19 PM

View PostMaurizio Domba, on 07 October 2012 - 11:58 AM, said:

There was a similar problem in the blog demo application... check this issue for a possible solution and explanation - https://github.com/y.../yii/issues/148

Is it possible to do it in my case like in blog demo?
0

#5 User is offline   Ruedi 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 9
  • Joined: 25-March 12

Posted 07 October 2012 - 12:31 PM

I can see only links to actions like:
<a class="delete" title="Delete" href="/demos/blog/index.php/post/delete?id=8"><img src="/demos/blog/assets/81dfc6af/gridview/delete.png" alt="Delete" /></a>
So there is no ajax calls on page http://www.yiiframew...php/post/admin.
0

#6 User is offline   Ruedi 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 9
  • Joined: 25-March 12

Posted 07 October 2012 - 12:41 PM

Also , I could not find anything valuable in blog demo source from yii 1.1.12 source. Where should I look?
0

#7 User is offline   Ruedi 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 9
  • Joined: 25-March 12

Posted 07 October 2012 - 01:10 PM

As alternative solution I can generate jquery code and ajax links by hardcode, not using ajaxLink function.
0

#8 User is offline   Ruedi 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 9
  • Joined: 25-March 12

Posted 08 October 2012 - 04:12 AM

I have tryed to put hardcoded links insted of generated by yii. I got an error when first call cart item is deleted and #cart-content is updated, on a next call to delete cart item link "delete" is not working. I can see in firebug that now ajax is executed two times. When I try to send request without ajax to delete php script I get cart item deleted and #cart-content content. Where is a problem? Please help. Thanks!

My links source code:
<a id="cartdelete-link-1" href="#">Delete</a>

My jquery source code:
<script type="text/javascript">
/*<![CDATA[*/
$('body').on('click','#cartdelete-link-0',function(){jQuery.ajax({'url':'index.php?r=cart/delete&id=0','cache':false,'success':function(html){jQuery("#cart-content").replaceWith(html)}});return false;});
$('body').on('click','#cartdelete-link-1',function(){jQuery.ajax({'url':'index.php?r=cart/delete&id=1','cache':false,'success':function(html){jQuery("#cart-content").replaceWith(html)}});return false;});
$('body').on('click','#cartdelete-link-2',function(){jQuery.ajax({'url':'index.php?r=cart/delete&id=2','cache':false,'success':function(html){jQuery("#cart-content").replaceWith(html)}});return false;});
/*]]>*/
</script>


There is some javascript error, becouse another ajax links are not working. Please advice any debugger to discover invalid code and error console.
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