On Sunday, June 12, 2011 7:11:10 PM UTC-4, 黄祥 wrote:
>
> pardon me, btw, what is the function of ajax_trap = True? what can do by
> ajax_trap = True?
> thank you so much.
>
ajax=True means the entire component is always loaded via Ajax (by calling
the web2py_component() function in /static/js/web2py_ajax.js) -- this
includes trapping any forms in the component, submitting them to the
component action via Ajax, and rendering the result in the component div.
ajax_trap=True is only relevant when ajax=False. When ajax=False, the
component is inserted in the page on the server side, before the parent page
is returned to the browser. In that case, if there is a form in the
component and you want the form submitted to the component action via Ajax,
then you have to set ajax_trap=True. Otherwise, the form will be submitted
normally and the entire page will be reloaded.
As Massimo suggested, if you've got a form in the component and would like
it trapped via Ajax, you're probably better off just setting ajax=True so
the whole component will always be loaded/reloaded via Ajax. Setting
ajax=False probably makes more sense when you just need to load the
component once and don't need any further interaction/reloading (i.e., no
forms).
This is explained in the book here:
http://web2py.com/book/default/chapter/13#Components
Anthony