Skip to content

Instantly share code, notes, and snippets.

@fajran
Created June 28, 2012 10:06
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 fajran/3010415 to your computer and use it in GitHub Desktop.
Save fajran/3010415 to your computer and use it in GitHub Desktop.
<script type="text/javascript">
function compute() {
var a = $('#value_a')[0].value;
var b = $('#value_b')[0].value;
$.ajax({
url: '/compute/?a=' + a + '&b=' + b,
success: function(data) {
$('#result').html(data);
}
});
}
</script>
<p>
a = <input type="text" name="a" id="value_a"/>
b = <input type="text" name="b" id="value_b"/>
a + b = <span id="result">...</span>
<button onclick="compute()">compute</button>
</p>
from django.http import HttpResponse
def compute(request):
a = int(request.GET['a'])
b = int(request.GET['b'])
c = a + b
return HttpResponse('%d + %d = %d' % (a, b, c))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment