Peeking at file "demo_app3/views/generic.load"

<<back Edit

1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
{{'''
# License: Public Domain
# Author: Iceberg at 21cn dot com

With this generic.load file, you can use same function to serve two purposes.

= regular action
- ajax callback (when called with .load)

Example modified from http://www.web2py.com/AlterEgo/default/show/252:

def index():
return dict(
part1='hello world',
part2=LOAD(url=URL(r=request,f='auxiliary.load'),ajax=True))

def auxiliary():
form=SQLFORM.factory(Field('name'))
if form.accepts(request.vars):
response.flash = 'ok'
return dict(message="Hello %s" % form.vars.name)
return dict(form=form)

Notice:

- no need to set response.headers['web2py-response-flash']
- no need to return a string
even if the function is called via ajax.

'''
}}{{if len(response._vars)==1:}}{{=response._vars.values()[0]}}{{else:}}{{=BEAUTIFY(response._vars)}}{{pass}}