hi, is it possible to use ajax callback to update session value in component? the same code on ajax callback is work fine when not in component (originally take from web2py appliance (estore) i've tested it and ended with duplicate session during ajax callback to update session value in component : *steps :* 1. choose dvd id = 2 with quantity 2 in sqlform.factory and submitted it 2. update the quantity into 1 in the checkout component
*result checked session value using response.toolbar()* purchase: 2: 1 2: 2 *code* *controllers/test.py* session.purchase = session.purchase or {} session_purchase = session.purchase def test(): return dict() def purchase_detail_callback(): id = int(request.vars.id) if request.vars.action == 'remove': del session.purchase[id] redirect(request.env.http_web2py_component_location, client_side = True) if request.vars.action == 'adjust_total_price': quantity = int(request.vars['quantity_%s' % id]) price = int(request.vars.price) *session.purchase[id] = quantity* total_price = quantity * price total_qty = 0 grand_total = 0 for calculation_id, calculation_quantity in session_purchase.items(): dvd = db.dvd(calculation_id) calculation_total_price = calculation_quantity * dvd.acquisition_price total_qty += calculation_quantity grand_total += calculation_total_price return "jQuery('#total_price_%s').html(%s); jQuery('#total_qty').html(%s); jQuery('#grand_total').html(%s);" % (id, total_price, total_qty, grand_total) *views/test/test.html* {{extend 'layout.html'}} {{=LOAD('test', 'purchase_cart.load', ajax = True, vars = {'reload_div':'map'} ) }} {{=LOAD('test', 'purchase_checkout.load', ajax = True, target = 'map') }} *views/test/purchase_checkout.load* {{total_qty = 0 }} {{grand_total = 0 }} <table class="table table-condensed table-hover"> <tr> <th>{{=T('DVD') }}</th> <th>{{=T('Price') }}</th> <th>{{=T('Quantity') }}</th> <th>{{=T('Total Price') }}</th> <th>{{=T('Action') }}</td> </tr> {{for id, qty in order.items():}} {{p = db.dvd(id) }} {{total_price = qty * p.acquisition_price}} {{total_qty += qty}} {{grand_total += total_price}} <tr> <td>{{=SPAN(p.title) }}</td> <td>{{=SPAN('Rp. %s' % format(p.acquisition_price, ",d") ) }}</td> <td> <form> <span class="col-xs-3"> <input name="{{='quantity_%s' % p.id}}" value="{{=qty}}" class="form-control" onkeyup="ajax('{{=URL('purchase_detail_callback', vars = dict(id = p.id, action = 'adjust_total_price', price = p.acquisition_price) ) }}', ['{{='quantity_%s' % p.id}}'], ':eval' )" /> </span> </form> </td> <td>Rp. {{=SPAN('%s' % format(total_price, ",d"), _id = 'total_price_%s' % p.id) }}</td> <td> {{=SPAN(A(I(_class='glyphicon glyphicon-remove-sign'), callback=URL('purchase_detail_callback', vars=dict(id=p.id, action='remove') ), delete='tr', _title='Remove from Order') ) }} </td> </tr> {{pass}} <tr> <td></td> <td>{{=B(T('Grand Total') ) }}</td> <td>{{=SPAN('%s' % format(total_qty, ",d"), _id = 'total_qty') }}</td> <td>Rp. {{=SPAN('%s' % format(grand_total, ",d"), _id = 'grand_total') }}</td> <td></td> </tr> </table> thanks and best regards, stifan -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- 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 web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.