well, you are hooking up to the event that gets fired every time an ajax
request completes.
you "trial" code just replace the fragment with a fixed value, but if you
use ajax instead the ajaxstop will fire in a loop, and it's correct that it
does it.
Why are you hooking up to the ajaxstop event instead of the change event on
the "quantity" field (as per your description on what is supposed to
happen) ?
On Thursday, August 1, 2013 7:25:10 PM UTC+2, Marco Prosperi wrote:
>
>
> hello, I would like to update the total in the view below (bottom of the
> message) when the user changes quantity. The following script works fine
> (fixed value)
>
> <script>
> jQuery(document).ready(function(){
> $(document).ajaxStop(function(){
> jQuery('#910').slideToggle();
> jQuery('#910').html('25.0');
> jQuery('#910').slideToggle();
> return false;
> });
> });
> </script>
>
> but if I replace the jQuery('#910').html('25.0');
> with:
>
> ajax("{{=URL(r=request,c='downld',f='order_reload')}}",[],'910');
>
> where:
>
> def order_reload():
> total=sum((qty*db.product(idx).price for idx,qty in
> session.cart.items()),0.0)
> return HTML(str(total))
>
> then after the first increment of qty the total gets refreshed
> continuously. How can I avoid this?
>
> thank you in advance, Marco
>
> p.s.: here is the view
>
> {{extend 'layout.html'}}
> <h1>Checkout</h1>
> <h2>Cart</h2>
> <table width="100%">
> {{for id, qty in cart.items():}}{{p=db.product(id)}}
> <tr>
> <td>{{=p.name}}</td>
> <td>€ {{=p.price}}</td>
> <td><span class="e" id="{{='item%s'%p.id}}">{{=qty}}</span>
> {{=A('add',callback=URL('cart_callback',vars=dict(id=p.id
> ,action='add')),target='item%s'%p.id,_class='button
> pill')}}{{=A('sub',callback=URL('cart_callback',vars=dict(id=p.id
> ,action='sub')),target='item%s'%p.id,_class='button pill')}}
> </td>
> </tr>
> {{pass}}
> <tr>
> <td>Total</td>
> <!-- <td>€{{=sum((qty*db.product(id).price for id, qty in
> cart.items()),0.0)}}</td> -->
> <td><div class="one" id="910">€ {{=sum((qty*db.product(id).price
> for id, qty in cart.items()),0.0)}}</div></td>
> </tr>
> </table>
>
>
>
--
---
You received this message because you are subscribed to the Google Groups
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.