Your first example is working because you are not using an Ajax callback -- the link is just a regular request for a full page. You second example doesn't redirect the whole page because the callback is an Ajax request -- so, the redirect just returns the redirect output as the Ajax response, and Ajax responses do not reload the whole page. Instead, you want to do a client-side redirect, which will reload the page via Javascript on the client side. Try:
redirect(URL('product'), client_side=True) Anthony On Wednesday, February 20, 2013 12:12:55 AM UTC-5, 黄祥 wrote: > > hi anthony, > > *controller : 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('order')) > if request.vars.action=='empty': > session.order.clear() > redirect(URL('product')) > return str(session.order[id]) > > def order_empty(): > session.order.clear() > redirect(URL('product')) > return locals() > > *## working with define another function called order_empty* > *views : order.html* > <table width="100%"> > {{for id, qty in order.items():}} > {{p=db.product(id)}} > <tr> > <td>{{=SPAN(p.product_name)}}</td> > <td>{{=SPAN('Rp. %s' % p.unit_price)}}</td> > <td>{{=SPAN(qty, _id='item_%s' % p.id)}}</td> > <td>{{=SPAN(A('Add', callback=URL('order_callback', vars=dict(id= > p.id, action='add')), target='item_%s' % p.id, _title='Add Quantity', > _class='btn btn-navbar'))}} {{=SPAN(A('Subtract', > callback=URL('order_callback', vars=dict(id=p.id, action='subtract')), > target='item_%s' % p.id, _title='Substract Quantity', _class='btn > btn-navbar'))}} {{=SPAN(A('Remove', callback=URL('order_callback', > vars=dict(id=p.id, action='remove')), delete='tr', _title='Remove %s from > Order' % p.product_name, _class='btn btn-navbar'))}}</td> > </tr> > {{pass}} > </table> > > *{{=SPAN(A('Empty', _href=URL('order_empty'), _title='Empty Order', > _class='btn btn-navbar'))}}* > *## Ending view order.html working* > > > *## not working with callback to order_callback* > *views : order.html* > <table width="100%"> > {{for id, qty in order.items():}} > {{p=db.product(id)}} > <tr> > <td>{{=SPAN(p.product_name)}}</td> > <td>{{=SPAN('Rp. %s' % p.unit_price)}}</td> > <td>{{=SPAN(qty, _id='item_%s' % p.id)}}</td> > <td>{{=SPAN(A('Add', callback=URL('order_callback', vars=dict(id= > p.id, action='add')), target='item_%s' % p.id, _title='Add Quantity', > _class='btn btn-navbar'))}} {{=SPAN(A('Subtract', > callback=URL('order_callback', vars=dict(id=p.id, action='subtract')), > target='item_%s' % p.id, _title='Substract Quantity', _class='btn > btn-navbar'))}} {{=SPAN(A('Remove', callback=URL('order_callback', > vars=dict(id=p.id, action='remove')), delete='tr', _title='Remove %s from > Order' % p.product_name, _class='btn btn-navbar'))}} </td> > </tr> > {{pass}} > </table> > > *{{=SPAN(A('Empty', callback=URL('order_callback', vars=dict(id=p.id, > action='empty')), target='item_%s' % p.id, _title='Empty Order', > _class='btn btn-navbar'))}}* > *## Ending view order.html not working* > > I mean it won't working for redirect function for example after i'm empty > the order, i want to redirect it to product.html. the one that currently > working is just empty my session data without redirect to product.html. > > any clues or suggestion to solve this? > > 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.