In the second and third cases, you delete session.order[id] but then try to return it, which will generate an error (so the response to the Ajax call will be a 500 error). This doesn't happen in the first case because the redirect happens before the return.
Anthony On Thursday, February 14, 2013 10:36:24 PM UTC-5, 黄祥 wrote: > > hi, > > i'm trying to delete session using del session, and found strange > behaviour > > for example > *#**views/default/order.html* > <table width="100%"> > {{for id, qty in order.items():}} > {{p=db.product(id)}} > <tr> > <td>{{=p.product_name}}</td> > <td>Rp. {{=p.unit_price}}</td> > <td><span id="{{='item%s'%p.id}}">{{=qty}}</span> > {{=SPAN(A('+', callback=URL('order_callback', vars=dict(id=p.id, > action='add')), target='item%s'%p.id, _title='Add Product', _class='btn > btn-navbar'))}} {{=SPAN(A('-', callback=URL('order_callback', vars=dict(id= > p.id, action='subtract')), target='item%s'%p.id, _title='Substract > Product', _class='btn btn-navbar'))}} *{{=SPAN(A('X', > callback=URL('order_callback', vars=dict(id=p.id, action='remove')), > delete='tr', _title='Remove Product', _class='btn btn-navbar'))}}*</td> > </tr> > {{pass}} > </table> > * > work* > *#controllers/default.py* > def order_callback(): > id=int(request.vars.id) > if request.vars.action=='add': > session.order[id]=session.order.get(id, 0)+1 > if request.vars.action=='subtract': > session.order[id]=max(0,session.order.get(id, 0)-1) > * if request.vars.action=='remove':* > * del session.order[id]* > * redirect(URL('product'))* > return str(session.order[id]) > * > not work* > *#controllers/default.py* > def order_callback(): > id=int(request.vars.id) > if request.vars.action=='add': > session.order[id]=session.order.get(id, 0)+1 > if request.vars.action=='subtract': > session.order[id]=max(0,session.order.get(id, 0)-1) > * if request.vars.action=='remove':* > * del session.order[id]* > * session.flash=T("Order Deleted!!!")* > return str(session.order[id]) > * > not work* > *#controllers/default.py* > def order_callback(): > id=int(request.vars.id) > if request.vars.action=='add': > session.order[id]=session.order.get(id, 0)+1 > if request.vars.action=='subtract': > session.order[id]=max(0,session.order.get(id, 0)-1) > * if request.vars.action=='remove':* > * del session.order[id]* > return str(session.order[id]) > > my question is it normal, or there is something error or lack in my code? > > thank you so much before > -- --- 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/groups/opt_out.