generic.load 859 B

123456789101112131415161718192021222324252627282930
  1. {{'''
  2. # License: Public Domain
  3. # Author: Iceberg at 21cn dot com
  4. With this generic.load file, you can use same function to serve two purposes.
  5. = regular action
  6. - ajax callback (when called with .load)
  7. Example modified from http://www.web2py.com/AlterEgo/default/show/252:
  8. def index():
  9. return dict(
  10. part1='hello world',
  11. part2=LOAD(url=URL(r=request,f='auxiliary.load'),ajax=True))
  12. def auxiliary():
  13. form=SQLFORM.factory(Field('name'))
  14. if form.accepts(request.vars):
  15. response.flash = 'ok'
  16. return dict(message="Hello %s" % form.vars.name)
  17. return dict(form=form)
  18. Notice:
  19. - no need to set response.headers['web2py-response-flash']
  20. - no need to return a string
  21. even if the function is called via ajax.
  22. '''}}{{if len(response._vars)==1:}}{{=response._vars.values()[0]}}{{else:}}{{=BEAUTIFY(response._vars)}}{{pass}}