Skip to content

Instantly share code, notes, and snippets.

@pgrunewald
Created May 30, 2017 16:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pgrunewald/84b2a4e9dffa27c62e3e3bc90f43f7b2 to your computer and use it in GitHub Desktop.
Save pgrunewald/84b2a4e9dffa27c62e3e3bc90f43f7b2 to your computer and use it in GitHub Desktop.
Browser view /w Ajax
from Products.Five.browser import BrowserView
class AjaxView(BrowserView):
"""Various callable methods.
"""
def plus(self):
return int(self.request.form('a')) + int(self.request.form('b'))
def minus(self):
return int(self.request.form('a')) - int(self.request.form('b'))
<browser:page
name="ajax_view"
for="*"
permission="zope2.Public"
class=".ajax_view.AjaxView"
allowed_attributes="plus
minus"
/>
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<script>
$.get("@@ajax_view/plus", {'a': 5, 'b': 5}, function(data) { document.write(data); });
$.get("@@ajax_view/minus", {'a': 5, 'b': 5}, function(data) { document.write(data); });
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment