index.tpl 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <!-- A simple application that shows how Bottle and jQuery get along.
  2. :copyright: (c) 2015 by Oz Nahum Tiram.
  3. :license: BSD, see LICENSE for more details.
  4. Inspired by the same example given in Flask
  5. :copyright: (c) 2015 by Armin Ronacher.
  6. -->
  7. <!doctype html>
  8. <title>jQuery Example</title>
  9. <script type="text/javascript"
  10. src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
  11. <script type="text/javascript">
  12. var $SCRIPT_ROOT = "{{ request.script_name }}";
  13. </script>
  14. <script type="text/javascript">
  15. $(function() {
  16. var submit_form = function(e) {
  17. $.getJSON($SCRIPT_ROOT + '_add_numbers', {
  18. a: $('input[name="a"]').val(),
  19. b: $('input[name="b"]').val()
  20. }, function(data) {
  21. $('#result').text(data.result);
  22. $('input[name=a]').focus().select();
  23. });
  24. return false;
  25. };
  26. $('a#calculate').bind('click', submit_form);
  27. $('input[type=text]').bind('keydown', function(e) {
  28. if (e.keyCode == 13) {
  29. submit_form(e);
  30. }
  31. });
  32. $('input[name=a]').focus();
  33. });
  34. </script>
  35. <h1>jQuery Example</h1>
  36. <p>
  37. <input type="text" size="5" name="a"> +
  38. <input type="text" size="5" name="b"> =
  39. <span id="result">?</span>
  40. <p><a href=# id="calculate">calculate server side</a>
  41. </body>
  42. </html>