It is difficult to provide you with help because you appear to be trying 
random syntax that you wish would work but is not based on anything in the 
documentation, and then we are left to guess what you are really trying to 
do. Instead of inventing your own syntax, try to stick to what you see and 
understand from the documentation. If there's something you can't figure 
out, it would be more productive for you to describe the functionality you 
want to achieve and let folks suggest possible implementations.

You can also probably do more debugging and discovery on your own. You can 
always inspect what's in request.vars, session, etc. by inserting them in 
your view, printing them to the console, or including 
{{=response.toolbar()}} in your view. You should also inspect the HTML code 
generated by web2py in your browser to see if your views are generating 
what you expect. Finally, learn how to use the developer tools in your 
browser so you can inspect the requests and responses sent and received by 
the browser -- that way you can see if your Ajax requests are working and 
sending and receiving the data you expect.

In this case, you have a form on the page for entering quantity, but your 
callback link doesn't do anything to extract the entered quantity and 
submit it back to the server, so request.vars.quantity and 
form.vars.quantity are always empty. Look into using the ajax() function.

Anthony

On Thursday, February 28, 2013 12:54:53 AM UTC-5, 黄祥 wrote:
>
> hi,
>
> i've tried to learn ajax callback using form(), but it's not work (no 
> error occured), did anyone know the solution for this?
> thank you very much before
>
> here is my code:
> *#controller*
> def order_callback():
>     id=int(request.vars.id)
>     quantity=int(request.vars.quantity)
>     if request.vars.action=='add':
>         session.order[id]=session.order.get(id, 0)+quantity
>     return str(session.order[id])
>
> def product():
>     rows=db((db.product.quantity>0) & (db.product.is_active == 
> True)).select(limitby=limitby, orderby=~db.product.id, cache=(cache.ram, 
> 10))
>     form=FORM(INPUT(_id='sale_quantity', _name='quantity', _type='text', 
> _size='3', requires = IS_NOT_EMPTY(error_message='cannot be empty!')))
>     return dict(rows=rows, form=form)
>
> *#view*
> *testing 1** not work no error occured:*
>     {{for i,row in enumerate(rows):}}
>     {{if i==items_per_page: break}}
>         <tr>
>             <td>{{=SPAN(row.product_name)}}
>             </td>
>             <td>{{=SPAN(session.order.get(row.id,0), _id="item%s"%row.id), 
> T(' In Order')}}
>             </td>
>             <td>{{=form}}
>             </td>
> *            <td>{{=A('Order Now!!!', callback=URL('order_callback', 
> vars=dict(id=row.id, quantity=request.vars.quantity, action='add')), 
> target='item%s'%row.id, _title='Add the Order', _class='btn btn-navbar')}}
> *
> *            </td>*
>         </tr>
>     {{pass}}
> *
> testing 2 not work no error occured:*
>     {{for i,row in enumerate(rows):}}
>     {{if i==items_per_page: break}}
>         <tr>
>             <td>{{=SPAN(row.product_name)}}
>             </td>
>             <td>{{=SPAN(session.order.get(row.id,0), _id="item%s"%row.id), 
> T(' In Order')}}
>             </td>
>             <td>{{=form}}
>             </td>
> *            <td>{{=A('Order Now!!!', callback=URL('order_callback', 
> vars=dict(id=row.id, quantity=form.vars.quantity, action='add')), 
> target='item%s'%row.id, _title='Add the Order', _class='btn btn-navbar')}}
> *
> *            </td>*
>         </tr>
>     {{pass}}
> *
>
> testing 3 not work no error occured:*
>     {{for i,row in enumerate(rows):}}
>     {{if i==items_per_page: break}}
>         <tr>
>             <td>{{=SPAN(row.product_name)}}
>             </td>
>             <td>{{=SPAN(session.order.get(row.id,0), _id="item%s"%row.id), 
> T(' In Order')}}
>             </td>
>             <td>{{=form}}
>             </td>
> *            <td>{{=A('Order Now!!!', callback=URL('order_callback', 
> vars=dict(id=row.id, quantity='quantity', action='add')), target='item%s'%
> row.id, _title='Add the Order', _class='btn btn-navbar')}}*
> *            </td>*
>         </tr>
>     {{pass}}
>

-- 

--- 
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.


Reply via email to