I have some HTML that Django is rendering well. I’d like to click a button on the HTML and have that cause an event to fire in the view.
It doesn’t look like the button is causing the post to fire. I’m not sure what I’m doing wrong.
This is my views.py code:
def log(request):
if not request.POST:
template = loader.get_template('log.html')
html = template.render(Context())
return HttpResponse(html)
print "Post"
This is my log.html:
<!DOCTYPE html>
<html>
<head>
<title></title>
<script type="text/javascript">
$("#update_log_button").bind("button", function(){
$.post("hello");
return false;
});
</script>
</head>
<body>
<p>
<span>SPHIINX Log</span>
</p>
<p>
<textarea cols="2" name="log" rows="25"></textarea>
<input id="update_log_button" name="update_log" type="button" value="Update Log"/>
</p>
</body>
</html>
Is there a reason Why you are not using the
clickevent directly?Try this:
If the button is dynamically created then you may want to use the
bindfunction to attachclickevent handler to the element:Try this URL to include the JQuery library: