web2py.transcription/views/generic.load

30 lines
875 B
Fish
Raw Normal View History

2021-10-01 10:29:16 +02:00
{{'''
# 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[next(iter(response._vars))]}}{{else:}}{{=BEAUTIFY(response._vars)}}{{pass}}